0

我有如下所示的 json,尽管这只是它的开始,而不是全部。

{"ns1:AmplifyResponse":{"AmplifyReturn":{"Topics":{"Domains":null,"TopTopics":[{"Topic":{"Name":"loo","Value":5.00},"

我正在执行此 jquery ajax 调用来获取它,再次对其进行修剪:

 $.ajax ({
    type: "POST",
    url: 'ajax/openampcheck.php',
    dataType: 'json',
    async: true,
    data: {"inputtext": inputmaintext},
    success: function(msg){
$('#oaresult').html(msg.ns1:AmplifyResponse.AmplifyReturn.Topics.TopTopics[1].Topic.Name);
....

在 Chrome 控制台中,这给了我一个错误... Uncaught SyntaxError: Unexpected token 。对于最后一行,这似乎与这里的冒号有关...

ns1:AmplifyResponse

如果我用引号括起来,即

$('#oaresult').html(msg."ns1:AmplifyResponse".AmplifyReturn.Topics.TopTopics[1].Topic.Name);

然后我得到这个错误:

Uncaught SyntaxError: Unexpected identifier 

我应该如何解决它?

4

2 回答 2

2
$('#oaresult').html(
              msg["ns1:AmplifyResponse"] // you have to use object["prop"] here
              .AmplifyReturn
              .Topics
              .TopTopics[1]
              .Topic.Name);

或者

$('#oaresult').html(msg["ns1:AmplifyResponse"]["AmplifyReturn"]["Topics"]["TopTopics"][1].["Topic"]["Name'});
于 2012-06-01T16:01:38.547 回答
1

尝试:

$('#oaresult').html(msg["ns1:AmplifyResponse"].AmplifyReturn.Topics.TopTopics[1].Topic.Name);
于 2012-06-01T16:01:45.940 回答