1

Hi below is my json string which is available in javascript

{
   "101":{"my":"1", "u":"4", "s":false, "isChecked":true},
   "102":{"my":"2", "u":"4", "s":false, "isChecked":false}
   .
   .
   .
   "1000":{"my":"999", "u":"888", "s":true, "isChecked":true}
}

Now -for example- I want to get the values of the isChecked property for each key:

  • "101" "isChecked" is true
  • "102" "isChecked" is false
  • ...
  • "1000" "isChecked" is true

Could please you share any useful snippet of code for this scenario?

Alberto De Caro
  • 5,147
  • 9
  • 47
  • 73
user2587669
  • 532
  • 4
  • 10
  • 22
  • what have you tried? Isn't it just.. var obj = JSON.parse('your json string'); obj['101'].isChecked == true ? – user1600124 Sep 12 '13 at 07:37
  • @DrixsonOseña looping is possible using `for in` as in `for (var key in object)` – Moazzam Khan Sep 12 '13 at 07:38
  • or use Object.keys(jsonObj) to get all the keys into an array – user1600124 Sep 12 '13 at 07:40
  • Please note that the problem has **nothing** to do with JSON at all, rather about how to process arrays and objects in JavaScript. *How* you obtained the data (e.g. via JSON) is irrelevant to the problem. See also: [There is no such thing as a "JSON object"](http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/). – Felix Kling Sep 12 '13 at 07:40

1 Answers1

0

Use for statement to go through the object:

var data = { /* your data here */ } 
for (var key in data) {
   console.log(key, data[key].isChecked);
}

http://jsfiddle.net/tZzfb/

Samich
  • 29,157
  • 6
  • 68
  • 77