admin管理员组文章数量:1022777
I have an external URL for a JSON file which is hosted on another domain (not mine). Is it possible to parse this information with javascript only? Here is a sample of the JSON data. I only want to get "q"
values.
[{"url":"/?q=who+is+ip+search","q":"who is ip search"},{"url":"/?q=eclipse+visual+editor","q":"eclipse visual editor"},{"url":"/?q=partition+recovery","q":"partition recovery"},{"url":"/?q=katzenfurz","q":"katzenfurz"},{"url":"/?q=rtfm","q":"rtfm"},{"url":"/?q=Google+ist+Dein+Freund","q":"Google ist Dein Freund"}]
I have an external URL for a JSON file which is hosted on another domain (not mine). Is it possible to parse this information with javascript only? Here is a sample of the JSON data. I only want to get "q"
values.
[{"url":"http://website./?q=who+is+ip+search","q":"who is ip search"},{"url":"http://website./?q=eclipse+visual+editor","q":"eclipse visual editor"},{"url":"http://website./?q=partition+recovery","q":"partition recovery"},{"url":"http://www.website./?q=katzenfurz","q":"katzenfurz"},{"url":"http://website./?q=rtfm","q":"rtfm"},{"url":"http://website./?q=Google+ist+Dein+Freund","q":"Google ist Dein Freund"}]
Share
Improve this question
edited Aug 5, 2012 at 12:11
Rustam
1,9332 gold badges16 silver badges35 bronze badges
asked Nov 20, 2011 at 12:47
bammabbammab
2,5737 gold badges26 silver badges28 bronze badges
4
- Check here. Or here Both have good explanation and samples. – Çağdaş Commented Nov 20, 2011 at 12:49
- I think this site could be what you are looking for. – Josh Mein Commented Nov 20, 2011 at 12:50
- 1 Just to add some history, JSON was originally used soley in JavaScript and means JavaScript Object Notation. So yes, JSON should be parseable with JavaScript. – kzh Commented Nov 20, 2011 at 14:13
- possible duplicate of Serializing to JSON in jQuery – outis Commented Dec 26, 2011 at 10:19
3 Answers
Reset to default 6Browsers have native parsing methods -> JSON.parse()
and JSON.stringify()
There are also several libraries that add the ability to parse JSON ...
- http://www.json/js.html
- http://developer.yahoo./yui/json/
- http://api.jquery./jQuery.parseJSON/
Eval is sometimes used directly within JavaScript - but there are often security concerns when using this method -> http://en.wikipedia/wiki/JSON#JavaScript_eval.28.29
Yes, there is a built-in JSON.parse()
function. Just pass the string to the function.
var obj = JSON.parse( data );
Live demo: http://jsfiddle/h4XTP/
JSON you know is JavaScript object; yes you can parse it in JS. Though as you have remote server as data publisher, you have to configure that server for a callback function. To make the remote request, you insert a new script tag into your page, which will allow you to specify a remote URL. The reponse back will load a JSON object as a parameter of the callback function you specified in the request.
Once read somewhere. Hope it helped.
I have an external URL for a JSON file which is hosted on another domain (not mine). Is it possible to parse this information with javascript only? Here is a sample of the JSON data. I only want to get "q"
values.
[{"url":"/?q=who+is+ip+search","q":"who is ip search"},{"url":"/?q=eclipse+visual+editor","q":"eclipse visual editor"},{"url":"/?q=partition+recovery","q":"partition recovery"},{"url":"/?q=katzenfurz","q":"katzenfurz"},{"url":"/?q=rtfm","q":"rtfm"},{"url":"/?q=Google+ist+Dein+Freund","q":"Google ist Dein Freund"}]
I have an external URL for a JSON file which is hosted on another domain (not mine). Is it possible to parse this information with javascript only? Here is a sample of the JSON data. I only want to get "q"
values.
[{"url":"http://website./?q=who+is+ip+search","q":"who is ip search"},{"url":"http://website./?q=eclipse+visual+editor","q":"eclipse visual editor"},{"url":"http://website./?q=partition+recovery","q":"partition recovery"},{"url":"http://www.website./?q=katzenfurz","q":"katzenfurz"},{"url":"http://website./?q=rtfm","q":"rtfm"},{"url":"http://website./?q=Google+ist+Dein+Freund","q":"Google ist Dein Freund"}]
Share
Improve this question
edited Aug 5, 2012 at 12:11
Rustam
1,9332 gold badges16 silver badges35 bronze badges
asked Nov 20, 2011 at 12:47
bammabbammab
2,5737 gold badges26 silver badges28 bronze badges
4
- Check here. Or here Both have good explanation and samples. – Çağdaş Commented Nov 20, 2011 at 12:49
- I think this site could be what you are looking for. – Josh Mein Commented Nov 20, 2011 at 12:50
- 1 Just to add some history, JSON was originally used soley in JavaScript and means JavaScript Object Notation. So yes, JSON should be parseable with JavaScript. – kzh Commented Nov 20, 2011 at 14:13
- possible duplicate of Serializing to JSON in jQuery – outis Commented Dec 26, 2011 at 10:19
3 Answers
Reset to default 6Browsers have native parsing methods -> JSON.parse()
and JSON.stringify()
There are also several libraries that add the ability to parse JSON ...
- http://www.json/js.html
- http://developer.yahoo./yui/json/
- http://api.jquery./jQuery.parseJSON/
Eval is sometimes used directly within JavaScript - but there are often security concerns when using this method -> http://en.wikipedia/wiki/JSON#JavaScript_eval.28.29
Yes, there is a built-in JSON.parse()
function. Just pass the string to the function.
var obj = JSON.parse( data );
Live demo: http://jsfiddle/h4XTP/
JSON you know is JavaScript object; yes you can parse it in JS. Though as you have remote server as data publisher, you have to configure that server for a callback function. To make the remote request, you insert a new script tag into your page, which will allow you to specify a remote URL. The reponse back will load a JSON object as a parameter of the callback function you specified in the request.
Once read somewhere. Hope it helped.
本文标签: Is it possible to parse JSON with javascriptStack Overflow
版权声明:本文标题:Is it possible to parse JSON with javascript? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745570717a2156719.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论