1

我应该如何解析这个json?

{"label":"KLM/AirFrance"}

我试试

jsonObject.getString("label")

但是有一个错误:

at org.json.JSON.typeMismatch

有任何想法吗?谢谢。

代码:

ArrayList<Gate> gates = new ArrayList<Gate>();
JSONArray jGates = object.getJSONArray("gates_info");
int gatesLength = jGates.length();
for (int i=0; i<gatesLength; i++) {
    Gate gate = new Gate();
    JSONObject jGate = jGates.getJSONObject(i);
    gate.setId(jGate.getInt("id"));
    gate.setLabel(jGate.getString("label"));
    gate.setCurrency_code(jGate.getString("currency_code"));
    gates.add(gate);
}

部分回复:

"gates_info":[{"id":48,"label":"KLM/AirFrance","payment_methods":
["card"],"currency_code":"usd","is_airline":true},
{"id":1,"label":"Nabortu","payment_methods":
["bank","yandex_money","web_money","terminal","card","svyaznoy","euroset"],
"currency_code":"rub","is_airline":false},    
{"id":3,"label":"anywayanyday.com","payment_methods": 
["card","euroset","svyaznoy"],"currency_code":"rub","is_airline":false},
{"id":7,"label":"Ozon.travel","payment_methods":
["cash","yandex_money","web_money","terminal","card","elexnet","contact","euroset"],
"currency_code":"rub","is_airline":false}, 
{"id":8,"label":"tickets.ru","payment_methods":
["card","web_money"],"currency_code":"rub","is_airline":false}
4

2 回答 2

1

Try to escape forward slash, i.e. write \\/. The back slash is written twice to escape itself, i.e. to make interpreter to treat it as a "real" back slash.

I have not tried this myself with JSON but typically such problems are solved using this kind of solutions.

于 2012-08-26T14:00:11.727 回答
0

在这里我遇到了这个问题(虽然它与转义字符无关。您只需要知道如何使用 Json。您需要使用 addProperty 函数:这是一个示例,您应该能够复制并获取它。

JsonObject temp = new JsonObject();
temp.addProperty(tagName,stringData);
于 2012-08-26T18:31:15.273 回答