简体   繁体   English

如何从使用php json_encode的链接解析数据

[英]How to parse data from link that is using php json_encode

I would like to parse data from a link, then put them into variables. 我想从链接中解析数据,然后将其放入变量中。 I have tried 我努力了

window.onload = function() {
    autoRefreshRadio();
};

function autoRefreshRadio(){
    var disabled = "Unavailable";
    var link = '{"url":"http://itspower.net/fullAPI.php"}';
    var obj = JSON.parse(link);
    alert(obj);
}

but it does not seem to alert anything. 但它似乎并没有任何提示。 I'm quite new to Javascript so any help would be appreciated. 我是Java的新手,因此可以提供任何帮助。

obj is a JS object. obj是一个JS对象。 If you want the link string, you need to reference the property it's stored it, url : 如果需要链接字符串,则需要引用存储它的属性url

function autoRefreshRadio(){
    var disabled = "Unavailable";
    var link = '{"url":"http://itspower.net/fullAPI.php"}';
    var obj = JSON.parse(link);
    alert(obj.url);
}

Although you're doing a lot of unnecessary legwork here. 尽管您在这里做了很多不必要的工作。 Just store the object in obj : 只需将对象存储在obj

function autoRefreshRadio(){
    var disabled = "Unavailable";
    var obj = {"url":"http://itspower.net/fullAPI.php"}
    alert(obj.url);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM