我的json文件看起来像这样
{ "Persons": { "Name" : "e","Name2": "e","Id": "4700" },[...] }
解决方法
这是(
http://youmightnotneedjquery.com/)的一个例子
request = new XMLHttpRequest(); request.open('GET','/my/url',true); request.onload = function() { if (request.status >= 200 && request.status < 400){ // Success! data = JSON.parse(request.responseText); } else { // We reached our target server,but it returned an error } }; request.onerror = function() { // There was a connection error of some sort }; request.send();
您的数据变量将具有如下可访问的成员:
警报(data.Persons.Name);