Json Parsing In Android: No Value For X Error
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet(url); request.setHeader('Accept', 'appl
Solution 1:
No value for x error
message is pretty common when dealing with JSON. This usually resulted by overlooked code.
usually, when dong JSON, I try to see the human readable structure first. For that, I usually use JSONViewer.
In your case, the structure is something like this:
You see that make
is within another object called GetJSONObjectResult
. Therefore, to get it, you must first get the container object first:
JSONObject vehicle = ((JSONObject)newJSONObject(result)).getJSONObject("GetJSONObjectResult");
//a more easy to readJSONObject container = newJSONObject(result);
JSONObject vehicle = container.getJSONObject("GetJSONObjectResult");
and finally use the object to get make
:
makeEdit.setText(vehicle.getString("make"));
plateEdit.setText(vehicle.getString("plate"));
modelEdit.setText(vehicle.getString("model"));
yearEdit.setText(vehicle.getString("year"));
Solution 2:
Your JSON Object contains itself a JSONObject. To acces to your data, you have to do like this:
vehicle.getJSONObject("GetJSONObjectResult").getString("make");
Post a Comment for "Json Parsing In Android: No Value For X Error"