java HashMap 的 JSON 表示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30266504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 16:47:37  来源:igfitidea点击:

JSON Representation of HashMap

javajsonhashmap

提问by samba

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

什么是 Json 表示HashMap<String, String>

I have tried this way but getting bad request error.

我已经尝试过这种方式,但收到了错误的请求错误。

"userPreferences":{{"mobile":"yes"},{"email":"yes"}}

回答by Learner

It should be like this

应该是这样的

{ "userPreferences":{"mobile":"yes","email":"yes"} }

回答by vidstige

"userPreferences":{"mobile":"yes","email":"yes"}

回答by C???

The JSON you have would be invalid even as a JavaScript object, since you haven't defined property names for the two "inner" objects. A HashMapis basically a set of key-value pairs. Your JSON should look like:

即使作为 JavaScript 对象,您拥有的 JSON 也是无效的,因为您尚未为两个“内部”对象定义属性名称。AHashMap基本上是一组键值对。您的 JSON 应如下所示:

"userPreferences": {
    "mobile": "yes",
    "email": "yes"
}