我正在创建一个cordova离子应用程序。我想创建一个像JSON一样的对象。我想发送一个像我需要动态创建的JSON请求。 以下只是一个例子。我想在JS中创建它。
{
user_id: "72",
data: {
[{
"id": "2",
"name": "1",
"occupation": "30",
"type": [{
"shape_id": "9",
"sizey": "6",
"sizex": "4",
"price": "6"
}, {
"shape_id": "8",
"sizey": "6",
"sizex": "6",
"price": "4.68"
}, {
"shape_id": "4",
"sizey": "4",
"sizex": "4",
"price": "2.08"
}],
}]
}
}
答案 0 :(得分:0)
只需使用您提供的内容并将其放入变量
即可您可以根据需要从号码中删除引号。没有引号,它将是一个数字而不是字符串
File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 357, in import_app
__import__(module)
File "/app/main.py", line 6, in <module>
from com.sears.mrp.handlers.ProductRuleHandler import ProductRuleHandler
File "/app/com/sears/mrp/handlers/ProductRuleHandler.py", line 1, in <module>
from google.appengine.ext import ndb
ImportError: No module named google.appengine.ext
[2016-11-28 09:10:17 +0000] [10] [INFO] Worker exiting (pid: 10)
[2016-11-28 09:10:17 +0000] [5] [INFO] Shutting down: Master
[2016-11-28 09:10:17 +0000] [5] [INFO] Reason: Worker failed to boot.*
If any one has faced this issue before please provide solution, I'm clueless on that to try more.
可以替换为
user_id : "72"
user_id : 72
答案 1 :(得分:0)
使用此:
jsonObj = [];
item = {}
item ["key"] = "value";
item ["key2"] = jsonObj2;
jsonObj.push(item);
答案 2 :(得分:0)
您可以创建一个javascript obj,如:
var obj={id: 2, name: "name"};
然后使用JSON.stringify(obj)
获取json字符串。