tags:

views:

98

answers:

2

How do I parse this? I'm working with WordPress and Jquery.

{
    "MyCustomOutput": [
        {
            "id": "2",
            "name": "This is the name of the custom output",
            "version": "1.00",
            "description": "This is the Description",
            "changelog": "This is the change log history....",
            "updated": "1261274072"
        }
    ]
}

I tried something like:

var d = JSON.parse(data);    
$("#version").html(data);
     $("#version").html(d.MyCustomOutput.version);

But I have no idea what I'm doing with Jquery... Or javascript :P

+3  A: 

To access data members:

d.MyCustomOutput[0].version

Also, it is helpful to use the FireBug firefox extension to debug your scripts. Just set a breakpoint to step through your code. You will have a "live" view of these data structures and can even add watches to test short code snippets to see if you are doing things correctly.

Justin Ethier
+4  A: 

Here's an explanation of what you're trying to do: http://www.json.org/js.html When content is within [], that's an array. When content is within {} that's an object.

Every member of an object can be accessed via "dot notation" much like you're trying to do. In your example, you could access version by it's object's index: d.MyCustomOutput[0].version.

In other words, your object has one member: MyCustomObject. That member has an array. Your array has one object.

I hope that helps.

Jim Schubert