Immediately comes the object, I do not know the keys.
{ "Ключ": Значение, "Ключ2": Значение, "Ключ3": Значение }
I do not understand how to parse it, help the slow-witted :) I need to derive both the key and the value.
Immediately comes the object, I do not know the keys.
{ "Ключ": Значение, "Ключ2": Значение, "Ключ3": Значение }
I do not understand how to parse it, help the slow-witted :) I need to derive both the key and the value.
JSON can contain values and collections of values. The simplified parsing algorithm is as follows:
JSON collection example:
{ "name" : "abc" , "email id " : ["abc@gmail.com","def@gmail.com","ghi@gmail.com"] }
JsonFactory factory = new JsonFactory(); ObjectMapper mapper = new ObjectMapper(factory); Map<String, Object> map = new HashMap<String, Object>(); // convert JSON string to Map map = mapper.readValue(json, new TypeReference<Map<String, String>>(){}); System.out.println(map);
where json
is a File
, InputStream
, Reader
or String
.
ArrayList<HashMap<String, Object>>
, but in HashMap<String, Object>
. Put in the map
and then add your map
to the List
or do something else with them. PS Answer added a little. - Pavel KrizhanovskiyMap
inside List
in this task? I suppose that you need either a list of pairs (of objects like Map.Entry
), or you can get by with the usual Map
. Revise your task in the direction of simplification. - iksuyJSON
into a map
. You are given a complete, comprehensive answer. To learn how to pass JSON to the ListAdapter , create a new question. - Pavel KrizhanovskiyCreate a class with a key, write getters - setters. Put them in the fox and chase him through GSON. He will parse himself from parse it into json from json'a.
Source: https://ru.stackoverflow.com/questions/507586/
All Articles