Js parses json, js converts json to map, and obtains key, value, and jsonmap of map.
Json string format
{ "10.10.11.1": { "target_1": "34.2", "target_3": "70.83", "target_2": "50.51", "target_5": "110.68", "c_event": "event", "target_4": "90.79", "c_timestamp": "12:54:34", "target_6": "10.2", "c_subject": "10.18.11.0" }}
{String, map <String, String >}similar to this format
Js functions:
function getValue(){var str = '{ "10.10.11.1": { "target_1": "34.2","target_3": "70.83","target_2": "50.51"}}';var map = eval("("+str+")");for (var key in map) { var a = map[key];for (var k in a) { alert(k+'---'+a[k]);} } }
Idea: parse the json string into a map object, but it is not supported in chrome.
When map is converted to json, the map key is converted to the json key.
You can use the syntax of JS for... in... to traverse all the keys and values in the object. The Code is as follows:
Var o = {"ret": {"2009051298180": [{"goods_price": 385, "goods_number": 1}], "2009051255518": [{"goods_price ": 960, "goods_number": 1}], "2009051268194": [{"goods_price": 0, "goods_number": 1}] }; var retObj = o. ret; for (var p in retObj) {// p is the key value you want alert (p + ':' + retObj [p]);}
Js json processing is the key-value mode. The key is dynamically obtained. The existing key-value Pair stuno, 001 json object is a, and I have obtained the key value.
Var str = '{"stuno": "0 "}';
Eval ('var json = '+ str );
// Var json = eval ('+ str + ')');
Alert (json. stuno); // The result is 0.
For (var name in json ){
Alert (name); // name result stuno
Alert (json [name]); // The result 0 is the same as the preceding result.
}
Or your requirements:
Var key = 'std ';
Alert (json [key]); // result 0 is the same as above
Yes ~