我应该如何解析这个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}
答案 0 :(得分:1)
尝试转义正斜杠,即写\\/
。
反斜杠被写两次以逃避自己,即使翻译将其视为真实的&#34;反斜杠。
我自己没有尝试使用JSON,但通常使用这种解决方案可以解决这些问题。
答案 1 :(得分:0)
这里我遇到了这个问题(它与转义字符无关。你只需要知道如何使用Json。你需要使用addProperty函数:这是一个例子,你应该能够复制它并得到它
JsonObject temp = new JsonObject();
temp.addProperty(tagName,stringData);