1

This is my JSON from PHP:

{"data" :
    [
        {
            "_id" : {
                "$id" : "4f977259b1445dce24000000"
            },
            "headline" : "asdfasdf",
            "date" : {
                "sec" : 1333584000,
                "usec" : 0
            },
            "text":"asdfasdfas"
        }
    ]
}

In Javascript I want to use the values and it works fine with

obj = JSON.parse(request);
console.log(obj.data[i].headline);

But how do I get the ObjectId?

It does not work like this:

console.log(obj.data[i]._id.$id);
1
  • I can verify that the answers gillesc and reach4thelasers work (at least in Safari). You may also want to have a look at stackoverflow.com/questions/2940424/… . Commented Apr 25, 2012 at 15:11

2 Answers 2

2

It seems to work as expected when I try it http://jsfiddle.net/2CSWr/

console.log(json.data[0]._id.$id);​

does output the right value

Sign up to request clarification or add additional context in comments.

Comments

0

This works for me:

console.log(obj.data[0]._id['$id']);

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.