I
I
Igor Bykov2018-11-29 07:59:59
Java
Igor Bykov, 2018-11-29 07:59:59

JSONObject changes dynamically, how to get around it?

JSONObject userInfo = jsonresponce.getJSONObject("ChampionLA54"); brsndP = userInfo.getString("brand"); artP = userInfo.getString("number"); nalP = userInfo.getString("availability");
desP = userInfo.getString("description");
} catch (JSONException e) {
e.printStackTrace();
}
but the variable "ChampionLA54" changes dynamically, how to parse the response bypassing "ChampionLA54", "GOTTWALDLA54", "Mahle/KnechtLA54"?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aleksey Solovyev, 2018-11-29
@alsolovyev

I am stupid (mixed up languages). Attempt number two in the comment
Не понял в чем проблема. Путь такой вариант будет: пройдитесь по каждому ключу(Object.keys()) в объекте:
for (var key in obj) {
    if (obj.hasOwnProperty(key)) {
        console.log(obj[key]); // print all object items 
    };
}

, где obj - объект респонса
ps или используйте Object.values(). Аналогично по значениям пройтись

A
aol-nnov, 2018-11-29
@aol-nnov

try to translate jackson into HashMap, and then take only the values.
https://www.mkyong.com/java/how-to-convert-java-ma...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question