Skip to content Skip to sidebar Skip to footer

Json Parsing And Storing Them In Variables

I am using Wamp server to create a database, and i have been able to retrieve them in android studio in JSON format, but I want to store them in variables, and the database in WAMP

Solution 1:

First convert the output json to a JSONObject and create an array through child objects. Again convert the children to Json objects and extract data:

String parentObject= newJSONObject(output);
String pumps= parentObject.optString("server_response").toString();
JSONArray childrenArray = newJSONArray(pumps);
for(int i=0; i < childrenArray.length(); i++)
{
   JSONObject childObject = childrenArray.getJSONObject(i);
   StringPump= childObject.optString("Pump").toString();
   StringAvailable= childObject.optString("Available").toString();
   //if (Available.equals("1")){Do something}
}

You may also directly use getString instead of optString if you are sure that object is not null and so you wont need to convert it toString()

Post a Comment for "Json Parsing And Storing Them In Variables"