让我们在这里明白,JSON只是Javascript对象表示法。所以,你所拥有的是几个对象:
{"hashcode":[], "stringMap":{":id":"50",":question":"My roof"}, ":size":"2", ":type":"java.util.HashMap", ":typeId":"123"}
下进一步打破这个代码,我们发现如下:
"hashcode":[] //an empty array named hashcode
"stringMap":{":id":"50",":question":"My roof"} //an object named stringMap with two properties, ":id" and ":question" (not sure why the : are there, this is abnormal)
":size":"2"//a string ":size" set to the string "2" (again, what's with the :?)
":type":"java.util.HashMap"//a string ":type" set to the string "java.util.HashMap"
":typeId":"123"//a string ":typeId" set to the string "123"
可以正常参考使用Javascript中“点”符号这些对象中的任何一个。整个事情的功能很像Java Enum/Hashmap/ArrayList。但是,由于那些“:”你在整个过程中都不起作用。通常情况下,虽然,你可以做以下(see POC here):
<script type="text/javascript">
var jsonString = '{"hashcode":[], "stringMap":{"id":"50","question":"My roof"}, "size":"2", "type":"java.util.HashMap", "typeId":"123"}';
var data = eval("(" + jsonString + ")");
alert(data.stringMap.id);
</script>
注意,为了让该代码工作,我不得不删除“:”从“ID” ......之前