0

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 !

4
  • Are you trying to read the json as plain String as it is ? Commented Feb 4, 2016 at 17:03
  • 1
    your json has parsing error. Commented Feb 4, 2016 at 17:06
  • 1
    That isn't valid json, is that the entire json in string form? You should catch and post your exception, it will likely give you more clarification. Commented Feb 4, 2016 at 17:06
  • @user3264924 If your editor does not help you validate your json. You can paste your JSON in jsoneditoronline.org and see where the error is. Commented Feb 4, 2016 at 17:22

1 Answer 1

1

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"
                }
            }
        }]
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you I found the solution!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.