Reputation: 1852
I started programming android and came across a problem with json.
I was trying to get the data as a string from the json, {"results":{"results_start":1,"results_returned":4,"api_version":"2.00","results_available":4,"school":[{"name_kana":"Cook","kyoten":{"name_kana":"CookTime","kyoten_type_cd":"TK","shiryo_url":{"qr":"http://webservice.recruit.co.jp/common/qr?url=https"}]}
.
I tried to use the code below to get the value from "name_kana" from the json data above with the following code but cannot get the string.
String name_kana="";
try{
JSONObject reader= new JSONObject(requestresult);
JSONArray school = reader.getJSONArray("school");
for (int i = 0; i < school.length(); i++) {
reader = school.getJSONObject(i);
}
name_kana = reader.optString("name_kana");
}catch(JSONException ex){
}
t = (TextView)container.findViewById(R.id.test);
t.setText(name_kana);
Since I'm new to android, would you mind if you can explain or provide me with the hints so that I can get the string data from the json mentioned above ? I would love to hear from you !
Upvotes: 0
Views: 61
Reputation: 7358
Your json is not parsing because it is not a valid json. Try using Jsonlint for validating your json.
The valid json seems to be this
{
"results": {
"results_start": 1,
"results_returned": 4,
"api_version": "2.00",
"results_available": 4,
"school": [{
"name_kana": "Cook",
"kyoten": {
"name_kana": "CookTime",
"kyoten_type_cd": "TK",
"shiryo_url": {
"qr": "http://webservice.recruit.co.jp/common/qr?url=https"
}
}
}]
}
}
Upvotes: 1