从JSON字符串获取值 [英] Get value from JSON string

查看:222
本文介绍了从JSON字符串获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下JSON字符串:

I have the following JSON string:

{"d":"{\"Foo\":7,\"Bar\":5,\"Foobar\":3}"}

以及我的js文件中的相应调用:

And the corresponding invocation in my js file:

$.getJSON("Foo.svc/GetSomeFoo", function (response) {
            alert(response["Foo"]);
            alert(response["Bar"]);
            alert(response["Foobar"]);
        });

只是尝试写出值,但似乎无法将其写出. 这可能很简单,但是在谷歌搜索时找不到任何有用的东西.

Just trying to write out the values, but can't seem to get it out. It is probably very simple, but I am not finding anything helpful while googling it.

推荐答案

您的JSON已嵌入JSON.您需要这样做:

Your JSON has embedded JSON. You need to do:

var d = JSON.parse(response.d);
alert(d.Foo);
...

这篇关于从JSON字符串获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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