iLearnToDev
iLearnToDev

Reputation: 13

display json from php in javascript

I have a php file returning this valid Json data, stored in a javascript variable named "json".

[
"564654.56464",
"848492.25477",
"918821.54471"
]

I try to display it in javascript with :

var object = JSON.parse(json);
document.write(object. ..... );

i don't know what to add here since my Json is not like {"attribute":"value","attribute2":"value2"

Upvotes: 0

Views: 72

Answers (2)

Vanco
Vanco

Reputation: 558

Use document.write(object.toString());

Upvotes: 0

CaptainCarl
CaptainCarl

Reputation: 3489

You can encode your PHP file along with a json header. I guess that should do the trick!

header('Content-Type: application/json');
echo json_encode($array);

Upvotes: 1

Related Questions