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

时间:2015-07-05 18:45:55

标签: java android json post

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

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

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

{"产品&#34 ;:  {" featured_src":" HTTPS:\ / \ / example.com \ /可湿性粉剂内容\ /上传\ / 2015 \ / 06 \ /sidney-compressed.jpg,  " short_description":"这是一个测试","标题":"来自北方的攻略"} }

我尝试了很多选项以保持上述格式。但它始终是{" featured_src":enter image description here

1 个答案:

答案 0 :(得分:0)

我们假设这是您的输入

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"}]}