[英]Read Json file data using javascript?
function uploadJsonFunction(){
var jsonURL = "C:\Users\My Documents\new\WebContent\JsonFiles\TreeJson\countries.json";
}
Here is my Json: 这是我的Json:
{
identifier: 'id',
label: 'name',
items: [
{
id: 'AF',
name: 'Africa',
type:'continent'
}
]
}
$.ajax({
url: "\countries.json",
success: function (data) {
var obj = JSON.parse(data);
}
});
For safety reasons, The C:\\Users\\My Documents\\new\\WebContent\\JsonFiles\\TreeJson\\countries.json
url won't work in a browser. 出于安全原因,
C:\\Users\\My Documents\\new\\WebContent\\JsonFiles\\TreeJson\\countries.json
url将无法在浏览器中运行。
Please try to see this example. 请尝试查看此示例。
Jquery to get Json Jquery得到Json
-or- -要么-
How to use a JSON file in javascript 如何在javascript中使用JSON文件
Hope may help you. 希望可以帮到你。
Why not to try Google: http://www.json.org/js.html 为什么不试试谷歌: http : //www.json.org/js.html
I used this for Android app that worked with PhoneGap(HTML+Javascript+JQuery) 我使用这个适用于使用PhoneGap的Android应用程序(HTML + Javascript + JQuery)
Worked fine. 工作得很好。
My Method: 我的方法:
var link_name = pathtojson.json
$.getJSON(link_name,
function(data){
var ttext = (data["SearchResponse"]["Translation"]["Results"][0]["TranslatedTerm"]);
document.getElementById('ttexti').innerHTML = ttext;
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.