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. Commented Apr 11, 2013 at 11:41
  • Well I wanted to parse to get the object.attribute, but my printed json has a different form Commented 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);
Sign up to request clarification or add additional context in comments.

Comments

0

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

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.