How do I to convert a JSON string to object in Java Android so that I can access "name2"
thanks
// this is how my json looks {"name1":"a","name2":"b","name3":"c","name4":"d"}
String mytext = GetMyJSON();
JSONObject obj = new JSONObject(mytext);
Strin N1 = obj.name1;
If a library is ok for you, GSON would help about it. it converts JSON to object, so you can reach them such as yourclassinst.name
refer this one
Do Something like this
JSONObject obj = new JSONObject(mytext);
if(obj!=null)
{
Strin N1 = obj.getString("name1");
Strin N2 = obj.getString("name2");
Strin N3 = obj.getString("name3");
Strin N4 = obj.getString("name4");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With