我的问题示例:
我们有一个类型为Apple的对象。Apple有一些成员变量:
String appleName; // The apples name
String appleBrand; // The apples brand
List<Seed> seeds; // A list of seeds the apple has
种子对象如下所示。
String seedName; // The seeds name
long seedSize; // The size of the seed
现在当我获取到一个苹果对象时,这个苹果可能有一个或多个种子,也可能没有任何种子!
带有一个种子的示例JSON苹果:
{
"apple" : {
"apple_name" : "Jimmy",
"apple_brand" : "Awesome Brand" ,
"seeds" : {"seed_name":"Loopy" , "seed_size":"14" }
}
}
一个带有两颗种子的苹果的JSON示例:
{
"apple" : {
"apple_name" : "Jimmy" ,
"apple_brand" : "Awesome Brand" ,
"seeds" : [
{
"seed_name" : "Loopy",
"seed_size" : "14"
},
{
"seed_name" : "Quake",
"seed_size" : "26"
}
]}
}
问题在于第一个示例是种子的JSONObject,第二个示例是种子的JSONArray。现在我知道它是不一致的JSON,最简单的修复方式是修复JSON本身,但不幸的是,我从别人那里获取JSON,因此我无法修复它。有什么最简单的方法可以解决这个问题?
:P
- jjnguy