Reputation:
I have an array that contains both english and russian data. I converted the array to json like this
echo json_encode(array(' list'=>$posts));
it converted the array but did not displayed the russian data properly, output was something like this
{" list":[{"id":"1","type":"\u0439\u0446\u0443\u043a\u0435\u043d","name":"","description":"","location":"","latitude":"","longitude":""},
{"id":"3","type":"","name":"Cafe","description":"","location":"","latitude":"","longitude":""}]}
to maintaing the russian data i converted the array in a different way, like this
echo json_encode($posts, 256);
and received the following output. conversion was done correctly but the problem is that the array did not got the array name "list" as it got in the previous output.
[{"id":"1","type":"йцукен","name":"","description":"","location":"","latitude":"","longitude":""},
{"id":"3","type":"","name":"Cafe","description":"","location":"","latitude":"","longitude":""}
I tried to combining both the method but that also didn't work. can anyone tell how i can get the array name in the second method
Upvotes: 0
Views: 116
Reputation: 173652
First of all, it should be easy to spot the difference when the statements are put side-by-side:
echo json_encode(array(' list'=>$posts));
echo json_encode($posts, 256);
What's being passed as the first argument is different, so at the very minimum you need this:
echo json_encode(array(' list'=>$posts), JSON_UNESCAPED_UNICODE);
Second, "\u0439\u0446\u0443\u043a\u0435\u043d"
is equivalent to "йцукен"
, so unless you have a very good reason for this, it's best to just work with the default options.
Upvotes: 1