what is the Json representation of HashMap<String, String>
?
I have tried this way but getting bad request error.
"userPreferences":{{"mobile":"yes"},{"email":"yes"}}
Make sure that you download the org. json jar file and put it in your classpath to be able to use the JSONObject. You can download the jar from here. In order to put each of those values into map as single key/value entry.
JSON is a text based object that different from HashMap.
The most traditional way of converting a hashmap to JSON object is by calling JSONObject() and then passing the hashmap. Let's take a look at an example that creates a hashmap and then prints it in JSON format.
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. We need to use the JSON-lib library for serializing and de-serializing a Map in JSON format.
It should be like this
{ "userPreferences":{"mobile":"yes","email":"yes"} }
"userPreferences":{"mobile":"yes","email":"yes"}
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