1

I am using Gson for parsing json response. I need to parse JSONArry inside JsonArray..

My response is..

{
"message": "Retreive sucessfully",
"flag": true,
"data": {
    "myArray1": [[{
        "xyz": "1400.0",
        "abc": "O",
        "mnp": "leeper"
    },
    {
        "xyz": "1400.0",
        "abc": "J",
        "mnp": "leeper"
    },
    {
        "xyz": "1400.0",
        "abc": "I",
        "mnp": "leeper"
    },
    {
        "xyz": "1400.0",
        "abc": "D",
        "mnp": "leeper"
    },
    {
        "xyz": "1400.0",
        "abc": "C",
        "mnp": "leeper"
    }],
    [{
        "xyz": "1400.0",
        "abc": "M",
        "mnp": "leeper"
    },
    {
        "xyz": "1400.0",
        "abc": "L",
        "mnp": "leeper"
    },
    {
        "xyz": "1400.0",
        "abc": "G",
        "mnp": "leeper"
    },
    {
        "xyz": "1400.0",
        "abc": "F",
        "mnp": "leeper"
    },
    {
        "xyz": "1400.0",
        "abc": "A",
        "mnp": "leeper"
    }]],
    "myArray2": [[{
        "xyz": "1000.0",
        "abc": "notaes",
        "mnp": null
    }],
    [{
        "xyz": "1400.0",
        "abc": "LS5",
        "mnp": "leeper"
    },
    {
        "xyz": "1400.0",
        "abc": "LS4",
        "mnp": "leeper"
    },
    {
        "xyz": "1400.0",
        "abc": "LS3",
        "mnp": "leeper"
    },
    {
        "xyz": "1400.0",
        "abc": "LS2",
        "mnp": "leeper"
    },
    {
        "xyz": "1400.0",
        "abc": "LS1",
        "mnp": "leeper"
    }],
    [{
        "xyz": "1000.0",
        "abc": "19",
        "mnp": "taes"
    },
    {
        "xyz": "1000.0",
        "abc": "notaes",
        "mnp": null
    },
    {
        "xyz": "1000.0",
        "abc": "notaes",
        "mnp": null
    },
    {
        "xyz": "1000.0",
        "abc": "notaes",
        "mnp": null
    },
    {
        "xyz": "1000.0",
        "abc": "notaes",
        "mnp": null
    },
    {
        "xyz": "1000.0",
        "abc": "notaes",
        "mnp": null
    },
    {
        "xyz": "1000.0",
        "abc": "notaes",
        "mnp": null
    },
    {
        "xyz": "1000.0",
        "abc": "notaes",
        "mnp": null
    },
    {
        "xyz": "1000.0",
        "abc": "notaes",
        "mnp": null
    },
    {
        "xyz": "1000.0",
        "abc": "notaes",
        "mnp": null
    }],
    [{
        "xyz": "1000.0",
        "abc": "notaes",
        "mnp": null
    },
    {
        "xyz": "1000.0",
        "abc": "notaes",
        "mnp": null
    },
    {
        "xyz": "1000.0",
        "abc": "20",
        "mnp": "taes"
    },
    {
        "xyz": "1000.0",
        "abc": "6",
        "mnp": "taes"
    },
    {
        "xyz": "1000.0",
        "abc": "3",
        "mnp": "taes"
    },
    {
        "xyz": "1000.0",
        "abc": "2",
        "mnp": "taes"
    }],
    [{
        "xyz": "1000.0",
        "abc": "notaes",
        "mnp": null
    },
    {
        "xyz": "1000.0",
        "abc": "1",
        "mnp": "taes"
    }]]
},
"code": "99"
}

What should be my class? I have done like this...

public class MyLayout {
public String message;
public boolean flag;
public Data data;
public String commandName;
public String code;

public class Data {
    public ArrayList<MyClass> myArray1 = new ArrayList<MyLayout.MyClass>();
    public ArrayList<MyClass> myArray2 = new ArrayList<MyLayout.MyClass>();
}

public class MyClass {
    public String abc;
    public String xyz;
    public String mnp;
}

}

It's not working??

EDIT

My Above MyLayout works when response is like below..But what about myArray item also contains JSONArray

{
"message": "Retreive sucessfully",
"flag": true,
"data": {
"myArray1": [{
    "xyz": "1400.0",
    "abc": "O",
    "mnp": "leeper"
},
{
    "xyz": "1400.0",
    "abc": "J",
    "mnp": "leeper"
},
{
    "xyz": "1400.0",
    "abc": "I",
    "mnp": "leeper"
},
{
    "xyz": "1400.0",
    "abc": "D",
    "mnp": "leeper"
},
{
    "xyz": "1400.0",
    "abc": "C",
    "mnp": "leeper"
}],
"myArray2": [{
    "xyz": "1400.0",
    "abc": "LS5",
    "mnp": "leeper"
},
{
    "xyz": "1400.0",
    "abc": "LS4",
    "mnp": "leeper"
},
{
    "xyz": "1400.0",
    "abc": "LS3",
    "mnp": "leeper"
},
{
    "xyz": "1400.0",
    "abc": "LS2",
    "mnp": "leeper"
},
{
    "xyz": "1400.0",
    "abc": "LS1",
    "mnp": "leeper"
}]
},
"code": "99"
}
5
  • what the problem? Your solution not works? Commented Mar 28, 2013 at 19:32
  • Yuap.. not working... Commented Mar 28, 2013 at 19:36
  • are you opposed to using JSON instead of Gson? Commented Mar 28, 2013 at 19:38
  • I am trying to explain MyClass is also having JSONArray. How to resolve that. Commented Mar 28, 2013 at 19:43
  • 1
    It's an array inside of an array. How would you handle it if it were a kumquat inside an array? You'd index the array to extract the kumquat and then operate on the kumquat. Commented Mar 28, 2013 at 19:56

1 Answer 1

3

myArray1 and myArray2 are arrays of arrays, so you'll need to modify Data to look like this:

public class Data {
  public List<List<MyClass>> myArray1 = ...
  public List<List<MyClass>> myArray2 = ...
}
Sign up to request clarification or add additional context in comments.

Comments

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.