【发布时间】:2015-10-09 05:14:53
【问题描述】:
我需要以编程方式构建下面的 JSON。但是,需要一种优雅的方式将 Java 对象转换为 JSON。这样,我就可以避免使用字符串生成器来构建下面的 JSON。
我知道,有时,在构建 JSON 时,我有一组特定键的参数。 请分享解决该问题的通用方法。
请分享一些想法。
{
"tropo": [
{
"ask": {
"attempts": 3,
"say": [
{
"value": "Hi.",
"event": "timeout"
},
{
"value": "Hello",
"event": "nomatch:1"
},
{
"value": "Hello2",
"event": "nomatch:2"
},
{
"value": "Satheesh",
"voice": "veronica"
}
],
"choices": {
"value": "Yes(1,Yes),No(2,No)",
"mode": "ANY"
},
"voice": "veronica",
"recognizer": "en-us",
"timeout": 8,
"name": "year",
"minConfidence": 39,
"required": true
}
},
{
"on": {
"next": "https://test.app.com/WAP2/",
"event": "continue"
}
},
{
"on": {
"next": "https://test.app.com/WAP2/",
"event": "incomplete"
}
},
{
"on": {
"next": "",
"event": "hangup"
}
}
]
}
【问题讨论】:
-
您可以使用 GSON 库。