如何在javascript中声明Json对象或变量 [英] How to declare a Json object or variable in javascript
本文介绍了如何在javascript中声明Json对象或变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var jsonQury = ?????
var json = ????
如何申报。
和wat我应该声明名称空间或程序集。
解决方案
请查看下面的链接:
如何使用jQuery创建JSON对象 [ ^ ]
JavaScript中的JSON [ ^ ]
这样的事情
数组:
< span class =code-keyword> var myJSONObject = { bindings:[
{ ircEvent: PRIVMSG, method: newURI,< span class =code-string> regex: ^ http://.*},
{ ircEvent: PRIVMSG, method: deleteURI, regex: ^ delete。*},
{ ircEvent: PRIVMSG, method: randomURI, regex: ^ random。*}
]
};
单个物品
< pre lang =Javascript> var myJSONObject = { ircEvent: PRIVMSG, method: newURI, regex: ^ http://.*};
>
创建一个空对象:
var JSONQury = {};
创建一个对象属性命名项和字符串中的值:
var JSONQury = {item:pen,price:15};
创建新对象:
var JSONQury = new Object();
示例哪个显示使用JSON在javascript中创建对象:
< !DOCTYPE html >
< html >
< head > ;
< title &G t; 使用JavaScript对象创建的JSON < / title >
< script language = javascript >
var JSONQury = {item :笔,制造:2014};
document.write(< h1 > 使用JavaScript的JSON < / h1 > 跨度>);
document.write(< br / > 跨度>);
document.write(< p > 项目名称=+ JSONQury.item +< / p > 跨度>);
document.write(< p > 制造于=+ JSONQury.manufactured +< / p > 跨度>);
< / script >
< / head >
< body >
< / body >
< / html > 跨度>
var jsonQury = ?????
var json = ????
How should i declare it.
and wat namespaces or assembly should i declare.
解决方案
Please have a look on the bellow link :
How to create JSON object using jQuery[^]
JSON in JavaScript[^]
some thing like this
for array:
var myJSONObject = {"bindings": [ {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"}, {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"}, {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"} ] };
for single object
var myJSONObject = {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"};
Creation of an empty Object:
var JSONQury = {};
Creation of an object with attribute named item and value in string:
var JSONQury = { "item ":"pen", "price":15 };
Creation of new object:
var JSONQury = new Object();
Example which shows creation of an object in javascript using JSON:
<!DOCTYPE html> <html> <head> <title>JSON with JavaScript Object Creation </title> <script language="javascript" > var JSONQury = { "item" : "pen", "manufactured" : 2014 }; document.write("<h1>JSON with JavaScript</h1>"); document.write("<br/>"); document.write("<p>Item Name="+JSONQury.item+"</p>"); document.write("<p>Manufactured in="+JSONQury.manufactured+"</p>"); </script> </head> <body> </body> </html>
这篇关于如何在javascript中声明Json对象或变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文