How to get key from json file using jquery

I have one example json file

{a:'spc432',
 b:'lll432'
}

I am trying to get a json file from the client side. and html are also written only on the client side. after that I want to find out every identifier from json file dynamically. How can we get identifiers with knowledge of the identifiers of json files ...? I tried under coding ... but it does not work. could you check

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-1.5.js"></script>
  <script>
        $(document).ready(function(){
            alert("hi");
            $.get("json_text.txt", function(data) 
                    { alert("length = "+data.length); 
                                          for( i = 0; i< data.length; i++)
                                             alert("key name "+data[i].id);
                                         }
                  );

        });
    </script>
</head>
<body>
</body>
</html>
+5
source share
2 answers

To get the key names you can do:

for(var key in data){ alert('key name: ' + key + ' value: ' + data[key]); }
+14
source
0

All Articles