是否可以使用javascript解析JSON? [英] Is it possible to parse JSON with javascript?

查看:105
本文介绍了是否可以使用javascript解析JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSON文件的外部URL,该URL托管在另一个域(不是我的域)上.是否可以仅使用javascript解析此信息?这是JSON数据的示例.我只想获取"q"值.

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.com/?q=who+is+ip+search","q":"who is ip search"},{"url":"http://website.com/?q=eclipse+visual+editor","q":"eclipse visual editor"},{"url":"http://website.com/?q=partition+recovery","q":"partition recovery"},{"url":"http://www.website.com/?q=katzenfurz","q":"katzenfurz"},{"url":"http://website.com/?q=rtfm","q":"rtfm"},{"url":"http://website.com/?q=Google+ist+Dein+Freund","q":"Google ist Dein Freund"}]

推荐答案

浏览器具有本机解析方法-> JSON.parse()JSON.stringify()

Browsers have native parsing methods -> JSON.parse() and JSON.stringify()

也有几个库添加了解析JSON的功能...

There are also several libraries that add the ability to parse JSON ...

  • http://www.json.org/js.html
  • http://developer.yahoo.com/yui/json/
  • http://api.jquery.com/jQuery.parseJSON/

Eval有时直接在JavaScript中使用-但使用此方法时通常会涉及安全问题->

Eval is sometimes used directly within JavaScript - but there are often security concerns when using this method -> http://en.wikipedia.org/wiki/JSON#JavaScript_eval.28.29

这篇关于是否可以使用javascript解析JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆