开发者

In Javascript/JQuery , how do I read a JSON file?

开发者 https://www.devze.com 2023-01-29 01:07 出处:网络
Let\'s say I have a JSON Object that is this: {\"success\":true, \"开发者_如何学Cuploaded_url\":uploaded_url}

Let's say I have a JSON Object that is this:

{"success":true, "开发者_如何学Cuploaded_url":uploaded_url}

How do I alert("uploaded_url")?


If it's a JSON file, say file.json, it would look like this:

$.getJSON("file.json", function(obj) {
  alert(obj.uploaded_url);
});

...it really depends how you're loading it, but it's just object.uploaded_url or object["uploaded_url"] once you have the object.


If you got a JSON string like this:

var myjson = '{"success":true, "uploaded_url":uploaded_url}'

you need to parse it into an javascript object first. Most convinient way is to use JSON.parse() which pretty much browsers support nowadays (if not, visit http://www.json.org)

var myobj = JSON.parse(myjson);
alert(myobj.uploaded_url);
0

精彩评论

暂无评论...
验证码 换一张
取 消