I have an array like this, which I json encode:
$regularArray = array(
array( "label" => "Hello World", "value" => 1 ),
array( "label" => "Hej Världen", "value" => 2 )
);
$jsonArray = json_encode( $regularArray );
(“Hej världen” means hello world in swedish) But when I print $jsonArray I get this:
[{"label":"Hello World","value":1},{"label":null,"value":2}]
Why is the label null for the second item in the array? I know it has to do with the word “Världen” since it contains a non-standard letter. How can I get around this?
json_encode function only works with UTF-8 encoded data. You may change your input array data to UTF-8.
Encode the input array data using utf8_encode and decode it whenever you need the data using utf8_decode
Output:-
I made a Test Page, it works fine.