简体   繁体   English

迭代一个json响应字符串?

[英]iterating a json response string?

How can i iterate my json string return from a Java file in JavaScript ? 我如何迭代从JavaScript中的Java文件返回的json字符串?

My JSON string having the following hierarchy; 我的JSON字符串具有以下层次结构;

ResponseObject -> SId -> SeId -> QId-> List of data . ResponseObject -> SId -> SeId -> QId-> List of data I need to access that list of data by looping through it using JavaScript. 我需要通过使用JavaScript循环访问该数据列表。

You can use jQuery to parse JSON String or alternatively, you can create a JSON Object using the javascript eval() function. 您可以使用jQuery解析JSON字符串,也可以使用javascript eval()函数创建JSON对象。

Once you have a JSON object created, you can use dot notation to traverse your json, like 创建JSON object ,您可以使用点表示法遍历JSON,例如

var value = ResponseObject.SId.SeId.Qid;

Where the attributes from the dot notation are your JSON key in the json string. 点符号的属性是json字符串中的JSON密钥。

Use this notation: myobjet["MyAttributeName"]. 使用此表示法:myobjet [“ MyAttributeName”]。

for( var SId in ResponseObject ) {

    for(var SeId in ResponseObject[SId] ) {

        for(var QId in ResponseObject[SId][SeId] ) {
            var value = ResponseObject[SId][SeId][QId];
        }

    }

}

I didn't test it, but it should work. 我没有测试它,但是应该可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM