Json_decode returns Null and Error 4
I am getting null when I decode my Json. $ contactInfo is a string from Java (Android) pushed through Volley. I checked the string, this is the string.
I have tried the following
1) Create $ contactInfo with only one user contact
2) Removed spaces
3) Remove special characters like β‘
4) Remove +
The closest solution I can find for reading such [[data, data], [data, data]] is using json decoding. Is there any other way for me to read this in an array or json?
$contactInfo = "[[john qiu, +16266169643], [Vince, +65 5888 8447]]"
$obj = stripslashes($contactInfo);
$obj = json_decode($obj);
echo json_last_error();
echo returns JSON_ERROR_SYNTAX
contactInfo, some users have special characters like "" "
source to share
The whole string must be wrapped in single quotes, which allows you to encapsulate json string segments in double quotes
<?php
$contactInfo = '[["john qiu", "+16266169643"], ["Vince", "+65 5888 8447"]]';
json_decode($contactInfo, true);
echo json_last_error();
?>
<b>output 0</b>
If your data is not formatted that way you might have to do some clever preg_replace
source to share