parse json with forward slash

How should I parse this json?

{"label":"KLM/AirFrance"}

I try

jsonObject.getString("label")

But have got an error:

at org.json.JSON.typeMismatch

Any ideas? Thanks.

Code:

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);
}

Part of response:

"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}

Answers


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.


Here I had this problem (it nothing to do with escape characters though. You just need to know how to use Json. You need to use the addProperty function: Here is an example you should be able to copy this and get it.

JsonObject temp = new JsonObject();
temp.addProperty(tagName,stringData);

Need Your Help

How to extract functions call graph from a visual basic file?

.net vb.net reverse-engineering legacy-code

I'm currently facing a large piece of legacy code which I have to understand and rewrite to make it more maintainable.