Java将JSON转换为application/x-www-form-urlencoded
作为输入,我有一个JSON,其结构如下:Java将JSON转换为application/x-www-form-urlencoded,java,json,forms,Java,Json,Forms,作为输入,我有一个JSON,其结构如下: { "amount": 2000, "currency": "usd", "description": "test charge" } 我需要发送一个请求,该JSON位于应用程序/x-www-form-urlencoded内容类型中。因此,数据的格式应该是amount=2000¤cy=usd&description=testcharge 我的以下逻辑如下所示: 使用Gson/Jackson将JSON解析为Map 创建泛型方法以生
{
"amount": 2000,
"currency": "usd",
"description": "test charge"
}
我需要发送一个请求,该JSON位于应用程序/x-www-form-urlencoded内容类型中。因此,数据的格式应该是amount=2000¤cy=usd&description=testcharge
我的以下逻辑如下所示:
Map
{
"amount": 2000,
"currency": "usd",
"shipping": {
"address": {
"city": "Seattle",
}
}
}
看起来怎么样?
amount=2000,currency=usd,shipping=???
这就是为什么我想使用库而不是我自己的解析..来回答第二个问题:接收者将如何使用传输的数据?它将被重新转换为json还是用于填充一些字符串值?@LalitMehra它将用于填充Html表单字符串值您可能需要为此编写一些转换和解析逻辑。可能会尝试将地址作为url参数发送到城市