0

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"

2
  • printed json and your explanation down is different? if you have "attribute":"value" then after parse you get value with object.attribute. Apr 11, 2013 at 11:41
  • Well I wanted to parse to get the object.attribute, but my printed json has a different form Apr 11, 2013 at 12:00

2 Answers 2

1

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

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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.