Reputation: 1295
I have to parse the following data
{"ResultSet":{"Query":"microsec fin","Result":
[{"symbol":"MICROSE_a.NS","name": "MICROSEC FIN SERV LTD ","exch": "NSI","type": "S","exchDisp":"NSE","typeDisp":"Equity"},
{"symbol":"MICROSEC.NS","name": "Microsec Fin Serv Ltd","exch": "NSI","type": "S","exchDisp":"NSE","typeDisp":"Equity"}]}}
The code i am using is
JSONObject json = (JSONObject) JSONSerializer.toJSON(inputLine);
symbol=json.getJSONObject("ResultSet").getJSONArray("Result").getJSONObject(0).getString("symbol");
which returns MICROSE_a.NS. What i want to do is if there is an undersore in symbol then i want the next symbol to be taken. That is now i want symbol to actually hold MICROSEC.NS. How do i do this.
Upvotes: 0
Views: 191
Reputation: 6487
Or which is much simpler with your library:
JSONArray Result= json.getJSONObject("ResultSet").getJSONArray("Result");
for(int i = 0; i<Result.length(); i++){
String symbol = Result.getJSONObject(i).getString("Symbol");
if(!symbol.contains("_"))
return symbol;
}
Upvotes: 1