我在使用gson
进行json解析时遇到了问题我的json文字是
{
**"message": [**
{
"id": "123",
"trackid": "GPN-GET-HYGH",
"category": "0",
"subject": "new message",
"dt": "2013-04-02 14:52:48",
**"message": "Hewlrj",**
"repliername": null,
"attachment_name": "image.jpg"
}
],
"replies": [
{
"id": "165",
"replyto": "123",
"name": "962788161885",
"message": "Hellooo\nHjkhjkhjkhkjh\nHjkhkjhjkhkh",
"dt": "2013-04-02 15:53:11",
"attachments": "",
"staffid": "0",
"rating": null
}
]
}
我创建了两个用于消息的第一个类,第二个用于回复上面的字段
但获得异常
com.google.myjson.JsonParseException: Expecting object found: "Hewlrj"
请帮帮我
EDITED
我的消息类结构看起来像(没有getter setter ..我已经删除了它)
public class message {
int id;
String trackid;
String category;
String subject;
String dt;
String message;
String repliername;
String attachment_name;
}
public class TicketList {
ArrayList<message> message;
}
try{
Gson json=new Gson();
object=json.fromJson(mJSONString,TicketLis.class);
}catch (Exception ex) {
System.out.println("error in gson parsing");
ex.printStackTrace();
}
答案 0 :(得分:0)
你的问题是你在json中有“消息”:“Hewlrj”,可能你定义了一个类似的类:
class Message {
private Message message;
}
因此Gson期望为消息找到一个json对象,但不是字符串。解决方案是将私有消息消息替换为私有String消息;