0

I am calling getTags web-method which returns hash-table in JSON format. following is return value which is formatted by

jQuery.parseJSON(JSON.stringify(response)) 

and assigned to variable jsonObj

I want read Key and Its value .How can I do this?

var jsonObj = {"getTags":[
                 {"Key":"TagID","Value":2},
                 {"Key":3,"Value":"Best College"}
                 ]
               }
Jakub
  • 20,418
  • 8
  • 65
  • 92
Shailesh
  • 13
  • 7
  • read this : http://www.mooforum.net/solutions12/json-key-value-output-t2265.html – xkeshav Jan 03 '12 at 05:52
  • possible duplicate of [How to retrieve key and value from JSON String](http://stackoverflow.com/questions/2927170/how-to-retrieve-key-and-value-from-json-string) – xkeshav Jan 03 '12 at 05:56

2 Answers2

0

var jsonObj = {"getTags":[{"Key":"TagID","Value":2},{"Key":3,"Value":"Best College"}]} for ( var i =0 ; i

guy mograbi
  • 27,391
  • 16
  • 83
  • 122
0

You made json bit complex by using "Keys" and "value" again as keys. Ideal JSON should be as given below:

var jsonObj ={
        "getTags": {
            "3": "Best College",
            "TagID": 2
        }
    }

Use below jquery to process this object:

var items=[];
 $.each(jsonObj, function(key, val) {
    // you can do whatever you want with key value pair.
    items.push(val);
  });
console.log(items); // items contains   ["Best College",2]

More help on jQuery.com

Umesh Patil
  • 10,475
  • 16
  • 52
  • 80