Java JSON对象中的URL作为POST请求

Java JSON对象中的URL作为POST请求,java,android,json,post,Java,Android,Json,Post,请帮助我在Android中通过HttpClient发送POST HTTP请求中的JSON对象 我面临的问题是,具有URL的JSON对象被正斜杠替换,即 最初,它在JSON对象中应该具有以下值 {“产品”: {“特色”src:“https:\/\/example.com\/wp content\/uploads\/2015\/06\/sidney-compressed.jpg, “简短描述”:“这是一次测试”,“标题”:“来自北方的袭击者”} } 我尝试了很多方法来保持上面的格式,但它总是以{“f

请帮助我在Android中通过HttpClient发送POST HTTP请求中的JSON对象

我面临的问题是,具有URL的JSON对象被正斜杠替换,即

最初,它在JSON对象中应该具有以下值

{“产品”: {“特色”src:“https:\/\/example.com\/wp content\/uploads\/2015\/06\/sidney-compressed.jpg, “简短描述”:“这是一次测试”,“标题”:“来自北方的袭击者”} }


我尝试了很多方法来保持上面的格式,但它总是以{“featured_src”的形式出现:

我们假设这是您的输入

private final static String JSON_DATA = "{"
        + "  \"product\": ["
        + "    {"
        + "      \"featured_src\": \"https:\\/\\/example.com\\/wp-content"
        + "\\/uploads\\/2015\\/06\\/sidney-compressed.jpg\","
        + "      \"short_description\": \"this is a test\","
        + "      \"title\" : \"Raiders from the North\""
        + "    }"
        + "  ]"
        + "}";
您可以使用
replace
来完成此操作

YOUR_STRING.replace("\\", "");
最后,通过将字符串作为参数传递,方法如下所示

private static String jsonUrlCorrector(String json_data) {
    json_data = json_data.replace("\\", "");
    return json_data;
}
以下是输入:

{"product":[{"featured_src":"https:\/\/example.com\/wp-content\/uploads\/2015\/06\/sidney-compressed.jpg","short_description": "this is a test","title":"Raiders from the North"}]}
这是输出

{"product":[{"featured_src":"https://example.com/wp-content/uploads/2015/06/sidney-compressed.jpg","short_description":"this is a test","title":"Raiders from the North"}]}

您的JSON是invalid@Arlind你能帮我克服前斜杠吗?请检查这个答案,以便了解你的问题,你想让你的URL看起来正确https:\\example.com\wp content\uploads….而不是\/\/?@maytham这些是反斜杠,URL应该有前斜杠,如http://