I try to parse json use jsontokener
This is my jsontokener code :
try {
JSONObject jObj = (JSONObject) new JSONTokener(strJson).nextValue();
String query = jObj.getString("query");
JSONArray location = jObj.getJSONArray("locations");
TextView tv = (TextView) findViewById(R.id.dummy_text);
tv.setText(query);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
TextView tv = (TextView) findViewById(R.id.dummy_text);
tv.setText("Wrong");
}
this is my first strJson :
String strJson = "{"
+ " \"query\": \"Pizza\", "
+ " \"locations\": [ 94043, 90210 ] "
+ "}";
and it will show
Pizza
and i try to change strJson to be like this :
String strJson = "{"
+ " \"component\": "
+ "{"
+ " \"query\": \"Pizza\", "
+ " \"locations\": [ 94043, 90210 ] "
+ "}"
+ "}";
and it will show
wrong
That mean code enter to catch.
please help me how to improve my code, so it can get query in component.