简体   繁体   English

我如何访问其中具有数据层次结构的Json对象

[英]how can i access Json object that have hierarchy of data inside it

i usally work with Json objects on my asp.net mvc by looping through the object and display the result such as 我通常通过遍历对象在asp.net mvc上使用Json对象并显示结果,例如

$.each(data, function (key, val) { 

                        // Format the text to display. 
                        var str = val.id + ': $' + val.packageName; 

                        // Add a list item for the product. 
                        $('<li/>', { text: str }) 
                        .appendTo($('#products')); 

But i came across a web service that return Json object in the following format that contains some sort of hireachy:- 但是我遇到了一个Web服务,该服务以以下格式返回Json对象,该格式包含某种形式的聘用:-

{
  "total":3,
  "desc":false,
  "sort":"name",
  "start":0,
  "data":
  [
    {"id":"hdc_v1001#1#hdc_certification_process",
      "packageName":"halal certification",
      "name":"HDC Certification Process",
      "packageId":"hdc_v1001",
      "label":"HDC Certification Process ver 1",
      "version":"1"},
    {"id":"mdec_v1002#12#mdec_wp1",
      "packageName":"Mdec Work Progress",
      "name":"mdec_wp1",
      "packageId":"mdec_v1002",
      "label":"mdec_wp1 ver 12",
      "version":"12"},
    {"id":"mora#5#mora_new_application",
      "packageName":"MORA Halal Certification",
      "name":"MORA New Application",
      "packageId":"mora",
      "label":"MORA New Application ver 5",
      "version":"5"}
  ]
}

So how i will be able to loop through the Json object in this case to displayed its values ? 那么,在这种情况下,我将如何遍历Json对象以显示其值? Best Regards 最好的祝福

myJsonObject = {
  "total":3,
  "desc":false,
  "sort":"name",
  "start":0,
  "data":
  [
    {"id":"hdc_v1001#1#hdc_certification_process",
      "packageName":"halal certification",
      "name":"HDC Certification Process",
      "packageId":"hdc_v1001",
      "label":"HDC Certification Process ver 1",
      "version":"1"},
    {"id":"mdec_v1002#12#mdec_wp1",
      "packageName":"Mdec Work Progress",
      "name":"mdec_wp1",
      "packageId":"mdec_v1002",
      "label":"mdec_wp1 ver 12",
      "version":"12"},
    {"id":"mora#5#mora_new_application",
      "packageName":"MORA Halal Certification",
      "name":"MORA New Application",
      "packageId":"mora",
      "label":"MORA New Application ver 5",
      "version":"5"}
  ]
};
$.each(myJsonObject.data, function (key, val) { 

                    // Format the text to display. 
                    var str = val.id + ': $' + val.packageName; 

                    // Add a list item for the product. 
                    $('<li/>', { text: str }) 
                    .appendTo($('#products')); 
}

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

相关问题 如何访问此JSON中的数据? - How can I access the data inside this JSON? 如何在nodejs中为数组/对象数据创建层次结构? - How can I create a hierarchy structure for a array/object data in nodejs? 我无法从JSON对象访问数据 - I can not access data from a JSON object 我有一个 json object 里面有数组 object,如何访问数组 ZA8CFDE6331BD59EB2AC96F8911C4B66Z - I have a json object with array object inside, how to access array object and if same product display only once and sum the price 如何访问对象内部的数据? - how do I access data inside object? 我有一个 json 数据,我想知道如何使用 fetch api 访问这些值? - I have a json data and I wanted to know how I can access the values using fetch api? 无法访问JSON对象中的单个数据:如何从JSON对象中将数据选出到VUE中 - Can't access individual data in JSON object: how do I single out data form a JSON object into VUE 如何在此api中访问此json对象? - How do I access this json object inside this api? 如何在不提及 javascript 中的名称的情况下访问 object 内部的命名 object 内部的重复元素数据? - How can I gain access to the repeating element data inside of a named object inside of an object without mentioning the name in javascript? 如何访问 object 内的 object 值? - How can I access object value that is inside the object?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM