내 자바 스크립트입니다 : 나는 같은 bulan
값에 얼마나 많은 type
을 계산하려는특정 JSON 개체 값에서 배열을 계산하는 방법은 무엇입니까?
var json = '{"GetReportIdResult":[{"bulan":"4","total":"1728","type":"CHEESE1K","uang":"8796383"},{"bulan":"4","total":"572476","type":"ESL","uang":"5863408410"},{"bulan":"4","total":"33507","type":"WHP","uang":"235653242"},{"bulan":"5","total":"4761","type":"CHEESE1K","uang":"134877865"},{"bulan":"5","total":"245867","type":"UHT","uang":"1446787280"},{"bulan":"5","total":"47974","type":"WHP","uang":"631929807"},{"bulan":"6","total":"5762","type":"CHEESE1K","uang":"293393832"},{"bulan":"6","total":"236803","type":"UHT","uang":"2219506085"},{"bulan":"6","total":"24853","type":"WHP","uang":"386175022"}]}';
obj = JSON.parse(json);
var arrayobj = obj.GetReportIdResult.length;
alert (arrayobj);
(예를 들면가 3 type
= CHEESE1K
, UHT
및 bulan
= 4 ESL
)
방법 하기 위해서?
당신의'json' 변수는 실제로 JSON (문자열)이 아니고 객체에 대한 참조가 할당되어 있으므로'JSON.parse (json)'을 사용할 필요가 없습니다. – nnnnnn
@nnnnnn 작전, 내 잘못 .. 하하, 나는 그것에 대해 잊어 버린다. : p 너에게 상기시켜 주셔서 감사합니다. – blankon91
이 데이터에 빈 배열 요소가 있습니다! –