0

i'm tring to parse url's json string to an json array.

ISSUE: json_decode = empty

QUESTION: Does anyone see what am i doing wrong?

MY STEPS:

tests from browser:

.....send.php?{"contactName":"name1"},{"contactName":"name2"}

my php code:

1. $url = $_SERVER['QUERY_STRING'];
2. $urlStringDecoded = urldecode($url);

echo urlStringDecoded result ok:

{"contactName":"name1"},{"contactName":"name2"}

3. $json = json_decode($urlStringDecoded, true);

RESULT EMPTY

echo("$json");
1
  • What's the name of that JSON query string property?? Commented May 19, 2016 at 12:45

2 Answers 2

2

Seems like your JSON is invalid. Wrap your current string within [ ] Brackets.

Eg.

<?php
$url = $_SERVER['QUERY_STRING'];
//echo $url;
$urlStringDecoded = urldecode($url);
echo $urlStringDecoded;
$json = json_decode("[".$urlStringDecoded."]", true);
echo "<pre>";
print_r($json);
echo "</pre>";
?>
Sign up to request clarification or add additional context in comments.

1 Comment

@OfirMalachi If it's helped, You can Mark answer as Accepted. Cheers!!
0

As you are trying to convert json string to json, you should provide right format. From you example it looks like you are passing , comma separated json objects whereas it should be an array. Add [] around your string and then try, in other words make it an array.

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.