I'm new to php and not sure why the go-daddy server treats JSON data differently. When I host it locally on my computer in local host, when I want to echo empty JSON array, I simply put [] shown as below. But when I uploaded the code to go-daddy server and try it out it echoed an error, Parse error: syntax error, unexpected '[', expecting ')' in...I'm wondering how can I put the JSON so it can echo [] when needed. Otherwise it will give "null" and when it parse into AS3, it turn into a JSON parse error.
if (!empty($output)){
echo json_encode( $output );}
else{
echo json_encode( [] );
}
JSON data has the concept of null and empty arrays and objects.
An empty string is not a valid json, then it fails.
If you want to represent a null value in JSON, the entire JSON string (excluding the quotes containing the JSON string) is simply null . No braces, no brackets, no quotes.
IsSuccessStatusCode && instituteDetails. Length>2) and if(createModel. Count()>0) worked fine if you getting empty jsonstring and model .
That is because your webserver version must be less than 5.4. You are trying to use a new feature of PHP 5.4 called the short array syntax
Use echo json_encode(array());
instead of echo json_encode( [] );
Working Demo on PHP v 5.3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With