I have a file test.json like that:
{
{"code":"ab","name":"Abkhaz","nativeName":"аҧсуа"},
{"code":"aa","name":"Afar","nativeName":"Afaraf"},
{"code":"af","name":"Afrikaans","nativeName":"Afrikaans"},
{"code":"ak","name":"Akan","nativeName":"Akan"},
{"code":"sq","name":"Albanian","nativeName":"Shqip"},
{"code":"am","name":"Amharic","nativeName":"አማርኛ"}
}
I need to convert in an array in php.
For that I have tried this but don't work :
$string = file_get_contents("test.json");
$json_array = json_decode($string, true);
print_r($json_array); //return empty
echo count($json_array); //return 0
This is the valid JSON (use http://pro.jsonlint.com/ to check your JSON strings, you need a start and end bracket [] instead of curly braces {}):
[
{
"code": "ab",
"name": "Abkhaz",
"nativeName": "аҧсуа"
},
{
"code": "aa",
"name": "Afar",
"nativeName": "Afaraf"
},
{
"code": "af",
"name": "Afrikaans",
"nativeName": "Afrikaans"
},
{
"code": "ak",
"name": "Akan",
"nativeName": "Akan"
},
{
"code": "sq",
"name": "Albanian",
"nativeName": "Shqip"
},
{
"code": "am",
"name": "Amharic",
"nativeName": "አማርኛ"
}
]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.