-1

Possible Duplicate:
I have a nested data structure / JSON, how can access a specific value?

{
"List":
  [
     {"Active":true,"Name":"VMW","Stores":
      [
        {"Active":true,"Name":"Admin"},{"Active":true,"Name":"sunil"}
      ]
     }
  ]
}

Its json data, how can I read it using Ajax or Javasricpt

Community
  • 1
  • 1
  • FYI, the expression "Ajax or Javascript" does not make much sense. "Ajax" is short for *Asynchronous JavaScript And XML*, i.e. Ajax is built on top of JavaScript. – Felix Kling Oct 13 '12 at 09:23

2 Answers2

1

The List and the store is an array, so to retrieve name and store's name, use array index like this :

jsondata.List[0].Name >>> return "VMW"
jsondata.List[0].Stores[0].Name >>> return "Admin"
Ta Duy Anh
  • 1,478
  • 9
  • 16
0
json = {
"List":
  [
     {"Active":true,"Name":"VMW","Stores":
      [
        {"Active":true,"Name":"Admin"},{"Active":true,"Name":"sunil"}
      ]
     }
  ]
}

json["List"]  // { "Active":true,"Name":"VMW","Stores": [{"Active":true,"Name":"Admin"},{"Active":true,"Name":"sunil"}]}


json["List"][0]["Stores"] // {"Active":true,"Name":"Admin"},{"Active":true,"Name":"sunil"}

is Stores for Object

Stores = json["List"][0]["Stores"]

for (i in Stores) (function(active, name) {


    console.log(active, name);
}(Stores[i]["Active"], Stores[i]["Name"]));

for results:

true "Admin"
true "sunil"
yasaricli
  • 2,433
  • 21
  • 30