私は質問を理解し、それがhtmlページでそれを使用するようにjsonファイルからデータを読み込んでいることに応じて、その回答になります。
//This is our Ajax function to load the JSON data
function ajaxLoad(path,callback){
try{
var response;
var xmlhttp =new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if(this.readyState==4&&this.status==200) {
response=this.responseText;
callback(response);
}
}
xmlhttp.open("POST",path,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send();
}
catch(e){
alert(e.message);
}
}
//now load the data
var itemsData;
var shellProds=[];
var arcoProds=[];
ajaxLoad("Items.json",function(data){
itemsData=JSON.parse(data);
for(i in itemsData.items){try{
if(itemsData.items[i].location=="shell"){
shellProds[i].itemid=itemsData.items[i].itemid;
shellProds[i].name=itemsData.items[i].name;
shellProds[i].price=itemsData.items[i].price;
}else{
arcoProds[i].itemid=itemsData.items[i].itemid;
arcoProds[i].name=itemsData.items[i].name;
arcoProds[i].price=itemsData.items[i].price;
}
//now you have loaded the data.
}
catch(e){
alert(e.message);
}
}
});
だから今は、ロードされたデータとの2つのオブジェクトの配列を持っています。
http://api.jquery.com/jquery.parsejson/ – Confused
@Confused:JSONを解析したいだけの場合は、jQueryの必要はありません。 –
もちろん、完全に可能です。 JavaScriptにはJSONの解析機能が組み込まれており、DOMにアクセスできます。 –