0

How can I convert this string into JSONArray ?

{"result":{"passion":[{"id":2,"description":"Sushi"},{"id":3,"description":"Dinner"},{"id":4,"description":"Sex"},{"id":5,"description":"Boobies"},{"id":6,"description":"Sleep"},{"id":7,"description":"Cars"},{"id":8,"description":"Travel"},{"id":9,"description":"Soccer"},{"id":10,"description":"Silice"}]}}

I'm trying to do:

 JSONArray jsonArray = jsonObject.getJSONArray("passion");

But I am getting an exception:

org.json.JSONException: No value for passion
5
  • 1
    There must be something you aren't showing us. Are you trying to access a JSON element named interest anywhere? Commented Oct 31, 2013 at 12:44
  • those are a mans passions right? Commented Oct 31, 2013 at 12:45
  • how do you get your jsonObject? Commented Oct 31, 2013 at 12:46
  • I've fixed it. Just need to create a new instance JSONObject Commented Oct 31, 2013 at 12:49
  • JSONObject jsonObject = new JSONObject(json); JSONObject values = jsonObject.getJSONObject("result"); JSONArray jsonArray = values.getJSONArray("passion"); Commented Oct 31, 2013 at 12:50

3 Answers 3

2

is seems like you are not getting result object

JSONArray jsonArray = jsonObject. getJSONObject("result").getJSONArray("passion");
Sign up to request clarification or add additional context in comments.

Comments

1

may be this is what you need dear

ArrayList<String> stringArray = new ArrayList<String>();
JSONArray jsonArray = new JSONArray();
for(int i = 0, count = jsonArray.length(); i< count; i++)
{
    try {
        JSONObject jsonObject = jsonArray.getJSONObject(i);
        stringArray.add(jsonObject.toString());
    }
    catch (JSONException e) {
        e.printStackTrace();
    }
}

Comments

0

Use this code

 JSONObject jsonObject = new JSONObject(json);
 JSONObject resultValues = jsonObject.getJSONObject("result"); 
 JSONArray passionArray = resultValues.getJSONArray("passion")

Comments

Your Answer

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