【问题标题】:parse json object in deeper hierarchy different解析更深层次的json对象不同
【发布时间】:2014-09-30 10:40:33
【问题描述】:

我的 JSON 是这样的:

   {
    "people":
       {
        "stuff":"OK",
        "name":"some reason",
        "content" : 
           {
            "name": "pet",
            "phone": "some value",
            "owner": "123"
           }
       },
    "machines":
        {
          "owner": 
           {
            "id": "123",
            "name": "peter"
           }
        }
    }

我的所有者类如下所示:

public class Owner {

@Expose
private String id;
@Expose
private String name;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}

我收到此错误:Expected BEGIN_OBJECT but was STRING 我为所有者做了一个 pojo,但我的问题是层次结构级别 3 上的所有者只是一个字符串,而在较低级别它是一个自定义对象。如何告诉我的解析器从不同于以前的第三级开始处理所有者对象?

【问题讨论】:

标签: java android json gson retrofit


【解决方案1】:
【解决方案2】:

好的,我刚刚创建了另一个同名的 Pojo + '_' 一个 pojo 包含所有者作为字符串,一个作为所有者对象。比想象的要容易,不需要解析

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-02
    • 1970-01-01
    • 2014-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多