2

This is my problem:

  • The user provides the following string in a text input element(It's a url to a location on google maps): https://www.google.com/maps/place/40%C2%B048'45.7%22N+73%C2%B036'22.2%22W/@40.8130626,-73.6039651,15z/data=!4m2!3m1!1s0x0:0x0?hl=en
  • I take the string value above via jquery along with some other text inputs, store it in an object, convert the values into a JSON String, and post it to the server for processing via ajax.
  • Once the server receives it(I use php on the server side), I take the JSON string and provide it as an argument for json_decode(). json_decode() returns null indicating that there was an error in the formatting of the JSON string it received. I know the part of the JSON string that was at fault was the one I listed above because my script works if it's not included.

My question is. How do I manipulate the string above to make it work with json_decode()? JSONLint.com tells me that the string above is valid JSON. I've looked at these following posts and tried out suggested solutions such as utf8_encode() and bin2hex() to clean up the string;however, json_decode() still returns null:

I now know that there are encoding issues; however, I'm at a loss with regards to how to make the string above compatible with json_decode(). I don't post on SO unless I'm really stuck with an issue, so any help is greatly appreciated.

Community
  • 1
  • 1
user3559356
  • 65
  • 1
  • 7
  • 1
    can you show us your JSON string – CY5 Sep 05 '15 at 05:14
  • Hmm. Can you decode that using `utf-8`? – aldrin27 Sep 05 '15 at 05:19
  • { "rowTitle": "test", "rowSubtitle": "test", "rowDescription": "", "rowBackgroundColor": "", "rowCompact": "", "rowFavorite": "", "rowImage": "", "linkName1": "google location", "linkRoute1": "www.google.com/maps/place/40%C2%B048'45.7%22N+73%C2%B036'22.2%22W/@40.8130626,-73.6039651,15z/data=!4m2!3m1!1s0x0:0x0?hl=en" } – user3559356 Sep 05 '15 at 05:20
  • I made 1 minor edit in the string above^. I deleted http:// from the url string, so that SO wouldn't use it as a link – user3559356 Sep 05 '15 at 05:23
  • Have you tried using [`json_last_error()`](http://us1.php.net/manual/en/function.json-last-error.php) to get the details of the error? – Ben Sep 05 '15 at 05:58
  • Yes, I got (int) 4 returned using json_last_error(). – user3559356 Sep 05 '15 at 06:15

0 Answers0