如何在JavaScript中JSON解码数组元素? [英] How to JSON decode array elements in JavaScript?

查看:185
本文介绍了如何在JavaScript中JSON解码数组元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JavaScript数组,其中包含一个URL。如果我尝试简单地将URL放在页面中(该数组位于涉及Yahoo! Maps API的项目中),它将显示URL应该是。

I have a JavaScript array that, among others, contains a URL. If I try to simply put the URL in the page (the array is in a project involving the Yahoo! Maps API) it shows the URL as it should be.

但是如果我尝试重定向或只是对链接数组元素执行警告,我得到:

But if I try to do a redirect or simply do an 'alert' on the link array element I get:


function(){return JSON .encode(this);}

function(){return JSON.encode(this);}

据我所知,这是因为浏览器在渲染时会执行JSON.encode页面,因此链接显示确定。我已经尝试了几种方法使其重定向(这是我想要对链接做的)正确(包括使用'eval')但没有运气。

As far as I see it this is because the browser does an JSON.encode when it renders the page, thus the link is displayed OK. I have tried several methods to make it redirect (that's what I want to do with the link) correctly (including the usage of 'eval') but with no luck.

在遵循一些建议之后我运行 eval('('+ jsonObject +')')但它仍然返回相同的输出。

After following some suggestions I've run eval('(' + jsonObject + ')') but it still returns the same output.

那怎么办呢?

推荐答案

var obj = jQuery.parseJSON('{"name":"John"}');
alert( obj.name === "John" );

请参阅jQuery API

这篇关于如何在JavaScript中JSON解码数组元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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