1

I have an issue with a json string.

I send this json string in Postman,

{
 "places": [
       {
         "longitude": "79.9304633",
         "latitude": "6.720229199999999",
         "city": "Panadura"
       },
       {
         "longitude": "79.86296829999999",
         "latitude": "6.855948499999999",
         "city": "Dehiwala"
       }
  ]
} 

But in the server side, when I get this value using this,

$jsonPlaces = $_POST['jsonplaces'];

and the value of $jsonPlaces looks like this,

{\\\"places\\\":[{\\\"longitude\\\":\\\"79.9304633\\\",\\\"latitude\\\":\\\"6.720229199999999\\\",\\\"city\\\":\\\"Panadura\\\"},{\\\"longitude\\\":\\\"79.86296829999999\\\",\\\"latitude\\\":\\\"6.855948499999999\\\",\\\"city\\\":\\\"Dehiwala\\\"}]}

therefore json_encode() function doesn't work for the above string since json syntax is changed. How to fix this issue?

Thanks

2
  • 3
    try using stripslashes($_POST['jsonplaces']) Commented Apr 12, 2015 at 11:04
  • yeah it worked, thanks, post this as a answer plz Commented Apr 12, 2015 at 11:07

2 Answers 2

3

Use stripslashes($_POST['jsonplaces']) to remove additional slashes.

Sign up to request clarification or add additional context in comments.

Comments

0

Probably Postman uses the addslashes method to escape the (JSON) string before inputing it in the DB, as mentioned in comment, you should use the inverse function stripslashes to un-escape the string before doing the json_decode function

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.