我正在接收JSON字符串的GWT应用程序,并且我很难找到每个对象的值。我试图将传入的JSON字符串转换为对象数组。GWT:处理传入的JSON字符串
这里是JSON(从Firebug的响应选项卡)中, “d” 是一个.NET的事情(Web服务正在消耗的C#。
{
"d": [
{
"__type": "Event",
"ID": 30,
"Bin": 1,
"Date": "\/Date(1281544749000)\/",
"Desc": "Blue with white stripes.",
"Category": "1"
},
{
"__type": "Event",
"ID": 16,
"Bin": 3,
"Date": "\/Date(1281636239000)\/",
"Desc": "Yellow with pink stripes",
"Category": "1"
}
]
}
我想给JSON解析成的对象,然后将它们插入到一个数组,我能够使用Window.alert
并得到整个“d”对象呼应。然而,当我尝试访问数组中的元素,GWT调试器只是崩溃。
//My GWT array to receive JSON Array
ArrayList<Item> itemInfo = new ArrayList<Item>();
//Getting response JSON into something I can work with.(THIS FAILS)
JSONArray jsonValue = JSONParser.parse(incomingJsonRespone);
//Just trying to verify I'm getting values
for (int i=0; i<jsonValue.size(); i++) {
JSONValue jsonItem = = JsonValue.get(i).getString();
Window.alert(jsonItem);
itemInfo.add(jsonItem);
}
我想我已经将问题缩小到了创建JSONArray
实例的位置。有没有什么公然错误的我如何尝试这样做,因为我没有得到太多的错误消息的帮助?
你可能想看看这个问题:http://stackoverflow.com/questions/3449099/parse-json-with-gwt-2-0/如果你信任你的源代码,你应该使用JavaScript Overlay Types。通过JSONParser解析JSON是一个PITA(但是当源不受信任时必须:/)。 – 2010-08-16 08:26:07