【发布时间】:2013-05-03 01:57:11
【问题描述】:
我正在尝试将 fusiontables sql 响应放入 android 中的 sqlite db。 jsonlint.com 说该对象是有效的 JSON。但是,“行”中的数组不被识别为 JsonArrays 或 JSONArrays。 sql 响应中的行数可能会有所不同。示例响应如下。我将不胜感激任何帮助为我指出正确的解决方案方向。甚至帮助我提出一个更好的问题。我被难住了!
{
"columns":"[Text, Number, Location, Date, ma, mb, mc, md, me, mf, mg, mh, mi, Xtid, JTid]",
"kind":"fusiontables#sqlresponse",
"rows":"[
[Text, 1.0, 33.2, -81.2, 2013-04-29T20:34:31.518-04:00, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 100.0],
[Text, 3.0, 33.2, -81.2, 2013-04-29T20:43:43.257-04:00, 24.0, 23.0, 18.0, 19.0, 54.0, 21.0, 31.0, 45.0, 32.0, 29.7, 58.1],
[Text, 5.0, 33.2, -81.2, 2013-05-01T06:58:09.801-04:00, 51.0, 51.0, 51.0, 51.0, 51.0, 51.0, 51.0, 51.0, 51.0, 51.0, 100.0],
[Text, 3.0, 33.2, -81.2, 2013-05-02T05:32:04.970-04:00, 52.0, 52.0, 52.0, 52.0, 52.0, 52.0, 52.0, 52.0, 52.0, 52.0, 100.0]
]"
}
//************ code
String json = SyncResponse.toString();
JsonObject root = parser.parse(json).getAsJsonObject();
System.out.println("root" + root); //this is where I got the JSON output listed above
【问题讨论】:
-
我不明白...您的 JSON 响应看起来如何?我的意思是,不是在解析之后,而是像你收到它一样......你的课
SyncResponse是什么,SyncResponse.toString()的结果是什么? -
SyncResponse 是来自 fustiontables sqlGet 查询的 sqlresponse。我发布的正是响应的内容。我刚刚发现这个问题的提及,我想它还没有修复。 Fusiontables issue 545
-
好的,所以我知道您不能像我在回答中所说的那样更改 JSON 响应,您必须在编写时解析 JSON 响应,对吧?
-
正确。有Gson方法还是需要使用String?
-
是的,你可以做点什么,我会更新我的答案...