|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
hey friends
i want to know that how to find no of attributes in any JSON object , actually what i am doing is creating dynamic JSON in ASP.net c# and then depot it to JAVASCRIPT . but i am not able to find no of attributes . if i can find id so it will be great help. do u guys know how to find no of attributes in any node of JSON, then do tell me. |
|
#2
|
|||
|
|||
|
Try using a for-in loop.
Code:
function jsonVarCount() {
var x = {
hello:function() {
alert('hello world');
},
foo: 'bar'
}
var y = [function() {
alert('hello world');
},'foo','bar']
var xCount = 0;
for(var a in x) xCount++;
var yCount = 0;
for(a in y) yCount++;
alert(xCount+','+yCount)
}
|
|
#3
|
|||
|
|||
|
i wil try it
so this means that there is no stright way we have to twist our finger. |
|
#4
|
|||
|
|||
|
You have to use the for-in loop to find the number of properties in a {}, but in a [] you can just check its length property.
|
|
#5
|
|||
|
|||
|
actually what i want is
i am exporting a datatable in javascript JSON OBJECT and i dont know the columns because they are comming dynamically. now i want ato find two things 1) the name of the attribute 2) the value of the attribute |
|
#6
|
|||
|
|||
|
That's easy enough.
Code:
var y = ['foo','bar']; for(var a in y) alert(a+' : '+y[a]); |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > How to find no of attributes in JSON |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|