I have the following Json page:
<?php
header('Content-Type: json; charset=utf-8');
$lottery = array(
array(
"id" => 0,
"navn" => "Vind telefon",
"udgiver" => "Telia",
"beskrivelse" => "Vind en Iphone 5 ved at gætte 1 spørgsmål",
"tilmeldte" => 89,
"startdate" => "10-04-2013",
"enddate" => "30-06-2013"
),
array(
"id" => 1,
"navn" => "Fri taletid",
"udgiver" => "Telmore",
"beskrivelse" => "Vind et års forbrug af fri data og fri taletid",
"tilmeldte" => 701,
"startdate" => "03-03-2013",
"enddate" => "10-06-2013"
),
array(
"id" => 2,
"navn" => "Vind 5000 kr.",
"udgiver" => "Bilka",
"beskrivelse" => "Vind et gavekort på 5000 kr til bilka.",
"tilmeldte" => 101,
"startdate" => "10-05-2013",
"enddate" => "01-07-2013"
),
array(
"id" => 3,
"navn" => "Fri vin",
"udgiver" => "Føtex",
"beskrivelse" => "Vind et års forbrug af vin",
"tilmeldte" => 391,
"startdate" => "01-04-2013",
"enddate" => "10-07-2013"
),
array(
"id" => 4,
"navn" => "Vind et TV",
"udgiver" => "El-giganten",
"beskrivelse" => "Vind et 60\" LED tv til stuen",
"tilmeldte" => 22,
"startdate" => "01-04-2013",
"enddate" => "22-07-2013"
),
array(
"id" => 5,
"navn" => "Vind en telefon",
"udgiver" => "Samsung",
"beskrivelse" => "Vind en Galaxy S4 4g telefon",
"tilmeldte" => 784,
"startdate" => "10-04-2013",
"enddate" => "30-07-2013"
),
array(
"id" => 6,
"navn" => "Gratis Vand",
"udgiver" => "Aqua D'or",
"beskrivelse" => "Vind et helt års forbrug af vand og dansk vand",
"tilmeldte" => 345,
"startdate" => "01-03-2013",
"enddate" => "18-07-2013"
),
array(
"id" => 7,
"navn" => "Fri Adwords",
"udgiver" => "Google",
"beskrivelse" => "Vind adwords kuponner til en værdi af 10.000",
"tilmeldte" => 22,
"startdate" => "10-02-2013",
"enddate" => "22-08-2013"
),
array(
"id" => 8,
"navn" => "Morgenmads produkter",
"udgiver" => "Kellogs",
"beskrivelse" => "Vind et helt års forbrug af kellogs produkter",
"tilmeldte" => 111,
"startdate" => "01-05-2013",
"enddate" => "10-09-2013"
),
array(
"id" => 9,
"navn" => "Vind tøjj for 10.000",
"udgiver" => "Jack & Jones",
"beskrivelse" => "Vind et gavekort til Jack & Jones på 10.000",
"tilmeldte" => 33,
"startdate" => "03-05-2013",
"enddate" => "01-10-2013"
)
);
//id, navn, udgiver, beskrivelse, tilmeldte, startdate, slutdate
echo json_encode($lottery);
All of the fields works fine but one!
the field beskrivelse returns is null when i open my json.
Here is a link to My Json
And here is the json in plain text
[
{
"id": 0,
"navn": "Vind telefon",
"udgiver": "Telia",
"beskrivelse": null,
"tilmeldte": 89,
"startdate": "10-04-2013",
"enddate": "30-06-2013"
},
{
"id": 1,
"navn": "Fri taletid",
"udgiver": "Telmore",
"beskrivelse": null,
"tilmeldte": 701,
"startdate": "03-03-2013",
"enddate": "10-06-2013"
},
{
"id": 2,
"navn": "Vind 5000 kr.",
"udgiver": "Bilka",
"beskrivelse": null,
"tilmeldte": 101,
"startdate": "10-05-2013",
"enddate": "01-07-2013"
},
{
"id": 3,
"navn": "Fri vin",
"udgiver": null,
"beskrivelse": null,
"tilmeldte": 391,
"startdate": "01-04-2013",
"enddate": "10-07-2013"
},
{
"id": 4,
"navn": "Vind et TV",
"udgiver": "El-giganten",
"beskrivelse": "Vind et 60\" LED tv til stuen",
"tilmeldte": 22,
"startdate": "01-04-2013",
"enddate": "22-07-2013"
},
{
"id": 5,
"navn": "Vind en telefon",
"udgiver": "Samsung",
"beskrivelse": "Vind en Galaxy S4 4g telefon",
"tilmeldte": 784,
"startdate": "10-04-2013",
"enddate": "30-07-2013"
},
{
"id": 6,
"navn": "Gratis Vand",
"udgiver": "Aqua D'or",
"beskrivelse": null,
"tilmeldte": 345,
"startdate": "01-03-2013",
"enddate": "18-07-2013"
},
{
"id": 7,
"navn": "Fri Adwords",
"udgiver": "Google",
"beskrivelse": null,
"tilmeldte": 22,
"startdate": "10-02-2013",
"enddate": "22-08-2013"
},
{
"id": 8,
"navn": "Morgenmads produkter",
"udgiver": "Kellogs",
"beskrivelse": null,
"tilmeldte": 111,
"startdate": "01-05-2013",
"enddate": "10-09-2013"
},
{
"id": 9,
"navn": null,
"udgiver": "Jack & Jones",
"beskrivelse": null,
"tilmeldte": 33,
"startdate": "03-05-2013",
"enddate": "01-10-2013"
}
]
Can anyone tell me why this is happening?
Jordan Doyle
3,0465 gold badges24 silver badges38 bronze badges
asked May 19, 2013 at 14:42
Marc Rasmussen
20.7k83 gold badges224 silver badges387 bronze badges
2 Answers 2
å is outside the range of ASCII, and therefore must be properly utf8-encoded. Try something like this:
"beskrivelse"=>utf8_encode("Vind et....")
answered May 19, 2013 at 14:44
Niet the Dark Absol
326k86 gold badges480 silver badges604 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Marc Rasmussen
This seems to do the trick however do you know how i can avoid the: " When ever my string is printed out it adds the qoutes
Gumbo
The UTF-8 encoded
å (0xC3A5) is also out of the range of ASCII (0x00–0x7F).If you try to encode an array containing non-utf values, you'll get null values in the resulting JSON string. You can batch-encode all the elements of an array with the array_map function:
<?php
$encodedArray = array_map(utf8_encode, $rawArray);
?>
answered May 19, 2013 at 15:04
Yogus
2,2705 gold badges23 silver badges40 bronze badges
Comments
lang-php
application/json.