开发者

Accessing JSON Object

If i have a JSON Obje开发者_JAVA百科ct

var Obj = { col1 : 'data' };

the value 'col1' and 'data' are dynamically created.

Here i can access 'data' as Obj.col1. But want to read the value 'col1'.

How to do that?


How about this:

for (var name in Obj) {
    alert(name)
} 


Assuming your column name is available from the JavaScript:

var columnName = "col1";
alert(Obj[columnName]); // alerts "data"

If 'col1' isn't present in the object, it fails gracefully returning null without raising an exception.

You may need to pass the the dynamic column name from serverside to clientside though. Something like:

var columnName = "<% columnName %>";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜