-4

I have JSON Response like this :

{
  "ResponseCode": "000",
  "ResponseDescription": "Successful",
  "ResponseData": [
    [
      "RequestID",
      "ProviderAuditID",
      "RequestTime",
      "Product",
      "ProductCode",
      "Currency",
      "Value",
      "ValueRes",
      "ValuePro",
      "TransactionResponseCode",
      "TransactionResponseDescription"
    ],
    [
      "23",
      null,
      "2013-07-22 07:09:06",
      "Test Product",
      "098",
      "India",
      "456.000000",
      "456.000000",
      "456.000000",
      null,
      null
    ],   
  ]
}

Now i want to parse this value and set it into the list view so can anyone help me out how to achieve this ???

EDIT ::

I have the multiple values in parsing,this is just an example ...

8
  • you might need to use multiple foreach loops Commented Aug 2, 2013 at 9:58
  • this is very bad approach to use JSON. Commented Aug 2, 2013 at 10:00
  • What do you want to do with it ? Instanciate a class with the same attributes ? Juste displaying the data? Commented Aug 2, 2013 at 10:02
  • You should use like "ResponseData": { "RequestID" : 23, "ProviderAuditID" : "id", ... } Commented Aug 2, 2013 at 10:02
  • @PankajKumar yes,i know but i have to done parsing this ways only.... no choice for me ,can u plz help me to achieve this ? :( Commented Aug 2, 2013 at 10:03

2 Answers 2

2

You have a wrapper object with an array in one of the fields. That field contains a List of String.

Parse your json into a JSONObject, then you can simply get your JSONArray and get the list inside it.

This should work:

JSONObject response = new JSONObject(json);
JSONArray jsonArray = response.getJSONArray("ResponseData");
for (int i = 0; i < jsonArray.length(); i++) {
    JSONArray arrValues = (JSONArray) jsonArray.get(i);
    // do what you have to do with the values
    for (int i = 0; i < arrValues.length(); i++) {
        String value = (String) arrValues.get(i);
    }
}
6
  • It May Work But I Check The AndroidLearner's JSON In jsonlint.com Its Wrong Commented Aug 2, 2013 at 10:49
  • It's wrong for the trailing comma, probably because he copied it wrong. Commented Aug 2, 2013 at 10:59
  • @Enrichman List<String> myList = (List<String>) jsonArray.get(i); this line shows me the java.lang.ClassCastException: org.json.JSONArray. Commented Aug 2, 2013 at 12:12
  • Hm... edited! Try this one. : ) Commented Aug 2, 2013 at 12:40
  • @Enrichman I got all the values,but how can i store this, because i want to display this thing in list view also.... Commented Aug 2, 2013 at 12:45
1

Please check your json data. using the following website -http://jsonlint.com/

Your json is not valid.

4
  • I have already checked the JSON in JSONLINT,Its 100 % vaild .. Commented Aug 2, 2013 at 10:05
  • Please check i am geting error in your json string. Commented Aug 2, 2013 at 10:11
  • This is not valid JSON. In particular, the trailing comma on the third last line is invalid. Commented Aug 2, 2013 at 10:26
  • @dpjanes Its a typo mistake.plz note my edit in my question where i have mentioned that there will be multiple records,this is just an example.so at the time of copying i forget to remove the comma.. Commented Aug 2, 2013 at 10:48

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.