这是我的json数据结构。它具有与此类似的大量数据。我正在使用杰克逊解析器来解析这个。
{
"dealers":
{
"google.com":{"id":1,"merchantname":"google","status":"active"},
"apple.com":{"id":2,"merchantname":"apple","status":"active"}
}
}
代码:
while (jParser.nextToken() != JsonToken.END_OBJECT) {
jParser.nextToken();
while (jParser.nextToken() != JsonToken.END_OBJECT) {
jParser.nextToken();
while (jParser.nextToken() != JsonToken.END_OBJECT) {
jParser.nextToken();
String fieldname = jParser.getCurrentName();
if (fieldname != null) {
if ("id".equals(fieldname)) {
jParser.nextToken();
if (jParser.getText() != null)
merchantID = jParser.getText();
else
merchantID = "";
}
if ("merchantname".equals(fieldname)) {
jParser.nextToken();
if (jParser.getText() != null)
merchantname = jParser.getText();
else
merchantname = "";
}
if ("status".equals(fieldname)) {
jParser.nextToken();
if (jParser.getText() != null)
name = jParser.getText();
}
}
}
}
}
数据未正确解析。搞砸了 jParser.nextToken() 方法。谁能指出这里的错误?