简体   繁体   English

如何在Json对象中打印数组

[英]How To Print Array inside Json Object

I got this Json String 我得到了这个Json String

{ "Banks": [ 
  { "BankNo": "TEST 5", "Name": "MAY", "Account": "987654", "BankCode": "ICBK", "Branch": "MAY" }, 
  { "BankNo": "TEST 6", "Name": "PETER", "Account": "987653", "BankCode": "ABOC", "Branch": "PETER" }, 
  { "BankNo": "TEST 7", "Name": "DAVID", "Account": "987652", "BankCode": "PCBC", "Branch": "DAVID" }, 
  { "BankNo": "TEST 8", "Name": "JOHN", "Account": "987651", "BankCode": "CMBC", "Branch": "JOHN" } 
] }

I try many way to print it out but fail... How I can loop one by one inside this Json? 我尝试了多种方法将其打印出来,但是失败了。如何在这个Json中一一循环?

The Result I expected is 1st Loop Print out BankNo : TEST 5 我预期的结果是1st Loop打印输出BankNo:TEST 5

2nd Loop Print out BankNo : TEST 6 第二次循环打印输出银行编号:TEST 6

try this 尝试这个

 var jn = { "Banks": [ { "BankNo": "TEST 5", "Name": "MAY", "Account": "987654", "BankCode": "ICBK", "Branch": "MAY" }, { "BankNo": "TEST 6", "Name": "PETER", "Account": "987653", "BankCode": "ABOC", "Branch": "PETER" }, { "BankNo": "TEST 7", "Name": "DAVID", "Account": "987652", "BankCode": "PCBC", "Branch": "DAVID" }, { "BankNo": "TEST 8", "Name": "JOHN", "Account": "987651", "BankCode": "CMBC", "Branch": "JOHN" } ] } //getting banks array var banks = jn.Banks banks.forEach((bank)=> { console.log(`${bank.BankNo}: ${bank.Name}`) }) 

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

相关问题 如何在对象内打印Javascript数据数组 - How to print Javascript data Array inside object 如何在JavaScript中加载和打印JSON数组/对象 - How to load and print json array/object in javascript 如何在 Z0ECD11C1D7A287401D148A23BBD7A2 数组中的 object 中获取 JSON object - How to get JSON object inside an object which is inside JSON array how to create an array of JSON objects, store them in a state array object and print the elements inside the render function in react-native - how to create an array of JSON objects , store them in a state array object and print the elements inside the render function in react-native 将[[object Object],[object Object]]打印到json数组 - print[ [object Object],[object Object]] to json array 在javascript中在数组内打印对象 - print object inside array in javascript 如何遍历数组里面的json object - How to iterate through the array inside json object 如何更改json数组中json对象中放置在数组中的值? - How to change a value placed inside a array in a json object in json array? 如何遍历另一个数组对象 (JSON) 中的数组对象? - How to Iterate through an array object inside another array object (JSON)? 如何在克隆的输入对象的值内打印嵌套数组? - How to print a nested array inside the value of a cloned input object?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM