Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON Representation of HashMap

Tags:

java

json

hashmap

what is the Json representation of HashMap<String, String>?

I have tried this way but getting bad request error.

"userPreferences":{{"mobile":"yes"},{"email":"yes"}}
like image 725
samba Avatar asked May 15 '15 18:05

samba


People also ask

How do I add a JSON response to a map?

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.

Does JSON use Hashmap?

JSON is a text based object that different from HashMap.

Can we convert Hashmap to object in Java?

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.

Can we have map in JSON?

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.


2 Answers

It should be like this

{ "userPreferences":{"mobile":"yes","email":"yes"} }
like image 178
Learner Avatar answered Sep 28 '22 04:09

Learner


"userPreferences":{"mobile":"yes","email":"yes"}
like image 31
vidstige Avatar answered Sep 28 '22 03:09

vidstige