0

Please help me to send a JSON object in POST HTTP request through HttpClient, in Android.

The problem I am facing is that the JSON object having the URL is replaced by forward slash ,i.e

originally it should have the following value in JSON object

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

i tried many options to keep it in the above format. But it always comes as {"featured_src": enter image description here

Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
Mosbius8
  • 119
  • 6

1 Answers1

0

We assume this is your input

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\""
        + "    }"
        + "  ]"
        + "}";

You could use replace to do the trick.

YOUR_STRING.replace("\\", "");

Finally your method would look like this, by passing your string as parameter

private static String jsonUrlCorrector(String json_data) {
    json_data = json_data.replace("\\", "");
    return json_data;
}

Here is the input:

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

Here is the output

{"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"}]}
Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137