0

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?

1
  • 1
    Is you PHP file actually encoded in UTF-8? By the way: JSON’s media type is application/json. Commented May 19, 2013 at 14:44

2 Answers 2

1

å is outside the range of ASCII, and therefore must be properly utf8-encoded. Try something like this:

"beskrivelse"=>utf8_encode("Vind et....")
Sign up to request clarification or add additional context in comments.

2 Comments

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
The UTF-8 encoded å (0xC3A5) is also out of the range of ASCII (0x00–0x7F).
0

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);
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.