Salah Owaidah Salah Owaidah - 1 year ago 111
JSON Question

Parsing JSON String Android

how can i parse such JSON string (but i have dynamic values)


most codes i saw before for static values, but i want help please thanks in advance.

Answer Source

I suggest Use JSONObject keys() to get the key and then iterate each key to get to the dynamic value.

according to your json string code must be something look like this:-

//refers to the current element in the array "data"
JSONObject mainObj = new JSONObject(yourString);
JSONObject dynamicValue1 = mainObj.getJSONObject("dynamicValue1");
Iterator key = dynamicValue1.keys();

while(key.hasNext()) {
    // loop to get the dynamic key
    String currentDynamicKey = (String);

    //get value of the dynamic key
    JSONObject currentDynamicValue = dynamicValue1.getJSONObject(currentDynamicKey);

    // here do something  with the other value...

I suggest to you can try this solution.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download