I have a JSON Array, I wanted to create dynamically a no of List<String> jsonFieldName base on the no of unique fields in the JSON response; Say for eg;
JSON = [{a:1,b:2,c:3},{a:4,b:5,c:5}];
result:
temp_array=[{a,b,c}];
based on the JSON sample above, I would end up with 3 new List;
list:
list a
list b
list c
I wanted to end up like these because, I wanted to create a generic JSON response parser wherein each response could differ in size/length.
How can I implement one in Android;
Here’s my existing method for parsing the JSON response
public void getJsonData(JSONArray ja) {
try {
// JSONArray jArray = new JSONArray(result);
for (int i = 0; i < ja.length(); ++i) {
JSONObject jo = ja.getJSONObject(i);
Log.i("Connect->getJsonData", jo.getString("tableno"));
}
} catch (Exception e) {
Log.e("ConnectToDatabase->getJsonData", "Error Parsing JSON Data "
+ e.toString());
}
}
Here’s what I did: