i'm working on Android with Eclipse. I'm writing a project where my app receives (also sends) data from a mysql database. I wrote a php file to make the project to work. I'm using JSON to communicate with the php file hosted in my local server. I don't have problems with the connection or similar problems but i receive this type of the json data:
{"field1":"A","field2":"abcbab","field3":5},
{"field1":"B","field2":"fakfef","field3":25},
{"field1":"A","field2":"faefe","field3":12},
{"field1":"C","field2":"aafefe","field3":30},
{"field1":"C","field2":"caere","field3":30},
etc..
Now my Android app has the target to create three different arrays (one for the type A of field1, one for the B and one for the C) to subsequent processing from the JSON data. I have two problems here.
I don't understand how to select a json value from a particular value of a field. I try to explain better, i know these instructions:
JSONObject json_data = new JSONObject(result);
json_data.getString("field1");
But how to say: "if field1 is A then put the value of field2 in arrayA1 and field3 in arrayA2", "if field1 is B then put the value of field2 in arrayB1 and field3 in arrayB2", "if field1 is C then put the value of field2 in arrayC1 and field3 in arrayC2". maybe I'm making it harder than it looks but i don't know i to do that. In this way i have two arrays for each type of field1, there is a better way to get what i want?. Remember: i can't change the code in the php file so the output that i get is always the rows shown above.