I have a JSONObject
with some attributes that I want to convert into a Map<String, Object>
Is there something that I can use from the json.org or ObjectMapper
?
A JSONObject is an unordered collection of name/value pairs whereas Map is an object that maps keys to values. A Map cannot contain duplicate keys and each key can map to at most one value.
You can map the data types of your business model into JSON by using the examples. Data in JSON is either an object or an array. A JSON object is an unordered collection of names and values. A JSON array is an ordered sequence of values.
A JSONObject has several methods such as get , opt and toString . If you have a JSONObject , you can easily convert it into a String using toString method. If you absolutely need JACKSON, you can try: JSONObject object = ...; ObjectMapper mapper = new ObjectMapper(); String jsonString = mapper.
To access the JSON object in JavaScript, parse it with JSON. parse() , and access it via “.” or “[]”.
use Jackson (https://github.com/FasterXML/jackson) from http://json.org/
HashMap<String,Object> result = new ObjectMapper().readValue(<JSON_OBJECT>, HashMap.class);
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