Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java将JSON转换为application/x-www-form-urlencoded_Java_Json_Forms - Fatal编程技术网

Java将JSON转换为application/x-www-form-urlencoded

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 创建泛型方法以生

作为输入,我有一个JSON,其结构如下:

{
  "amount": 2000,
  "currency": "usd",
  "description": "test charge"
}
我需要发送一个请求,该JSON位于应用程序/x-www-form-urlencoded内容类型中。因此,数据的格式应该是
amount=2000¤cy=usd&description=testcharge

我的以下逻辑如下所示:

  • 使用Gson/Jackson将JSON解析为
    Map
  • 创建泛型方法以生成键值字符串
  • 我的第一个问题:是否有用于将JSON转换为application/x-www-form-urlencoded的Java库?或者没有任何用于构建键值url编码对的库

    如果没有图书馆,这也不是什么大事,但是

    我的第二个问题:如果给定的json将包含一些嵌套对象/数组,那么应用程序/x-www-form-urlencoded查询的外观如何

    {
      "amount": 2000,
      "currency": "usd",
      "shipping": {
        "address": {
          "city": "Seattle",
          }
       }
    }
    
    看起来怎么样?
    amount=2000,currency=usd,shipping=???


    这就是为什么我想使用库而不是我自己的解析..

    来回答第二个问题:接收者将如何使用传输的数据?它将被重新转换为json还是用于填充一些字符串值?@LalitMehra它将用于填充Html表单字符串值您可能需要为此编写一些转换和解析逻辑。可能会尝试将地址作为url参数发送到城市