1
我试图商店以下使用中的NodeJS谷歌数据存储对象,但其返回400“错误的请求”错误节点:如何存储JSON数组在谷歌数据存储
{
\t \t \t "_id":{
\t \t \t \t "$oid":"567e9e80067de880273095e0"
\t \t \t \t },
\t \t \t \t "name":"Windows 10",
\t \t \t \t "desc":"This is a Test",
\t \t \t \t "isSelfPaced":true,
\t \t \t \t "credit":[
\t \t \t \t {
\t \t \t \t "_id":"56640d4926b67c201b861cde",
\t \t \t \t "username":"Akash",
\t \t \t \t "displayName":"Gupta",
\t \t \t \t "email":"[email protected]",
\t \t \t \t "role":"Author"
\t \t \t \t }
\t \t \t \t ],
\t \t \t \t \t \t \t \t
\t \t \t \t "video":{
\t \t \t \t "type":0,
\t \t \t \t "videoKey":"KHATEmotionalFulls_lowb84c0084-836c-008c-a850-328687e23d02.mp4",
\t \t \t \t
\t \t \t \t },
\t \t \t \t "structure":4,
\t \t \t \t "category":"test2",
\t \t \t \t "subCategory":"dfdfdf",
\t \t \t \t "content":[
\t \t \t \t {
\t \t \t \t "id":"a053915c-8d10-4aa8-b464-c8a99154c3af",
\t \t \t \t "name":"Module 1",
\t \t \t \t "type":1,
\t \t \t \t "topics":[
\t \t \t \t "test1",
\t \t \t \t "test2"
\t \t \t \t ],
\t \t \t \t "children":[
\t \t \t \t {
\t \t \t \t "id":"46f18a1a-6653-41cb-be5c-002200170bb9",
\t \t \t \t "name":"Unit 1",
\t \t \t \t "type":2,
\t \t \t \t "subtype":"1",
\t \t \t \t "video":{
\t \t \t \t "type":0,
\t \t \t \t "videoKey":"VID-20150920-WA0017ee56049d-2b08-aeb5-9b9c-b5188b1f7324.mp4",
\t \t \t \t
\t \t \t \t },
\t \t \t \t "note":"<ul><li><b>This is a test<\/b><\/li><\/ul>",
\t \t \t \t "isSelfPaced":true
\t \t \t \t },
\t \t \t \t {
\t \t \t \t "id":"da4f53a3-7ea2-4fa8-9d48-4d7199a3450c",
\t \t \t \t "name":"quiz 1",
\t \t \t \t "type":2,
\t \t \t \t "subtype":3,
\t \t \t \t "questions":[
\t \t \t \t {
\t \t \t \t "question":"New Question",
\t \t \t \t "options":[
\t \t \t \t {
\t \t \t \t "text":"option 1",
\t \t \t \t "correct":true
\t \t \t \t }
\t \t \t \t ]
\t \t \t \t }
\t \t \t \t ],
\t \t \t \t "isSelfPaced":true
\t \t \t \t }
\t \t \t \t ],
\t \t \t \t "time":3,
\t \t \t \t "isSelfPaced":true,
\t \t \t \t "desc":"This is a test"
\t \t \t \t }
\t \t \t \t ],
\t \t \t \t "createdBy":{
\t \t \t \t "displayName":"Gupta",
\t \t \t \t "id":"56640d4926b67c201b861cde"
\t \t \t \t },
\t \t \t \t "createdAt":{
\t \t \t \t "$date":"2016-01-10T17:51:15.635Z"
\t \t \t \t },
\t \t \t \t "startDate":"1970-01-01T00:00:00.000Z",
\t \t \t \t "endDate":"1970-01-01T00:00:00.000Z",
\t \t \t \t "isPublish":true
\t \t \t \t };
\t datastore.insert('test2','test2',data,function(err,key){
\t \t if(err){
\t \t \t res.status(500).end();
\t \t }
\t \t else{
\t \t \t res.send(key);
\t \t }
\t });
\t });
代码的NodeJS :
var keyObject = dataset.key({
\t \t namespace: namespace,
\t \t path: [collectionName,utility.getGUID()]
\t \t });
\t dataset.save({key:keyObject,data:data,method:'insert'},function(err) {
\t \t if(err){
\t \t \t callback(err,null);
\t \t }
\t \t else{
\t \t \t callback(null,keyObject.path[1]);
\t \t }
\t \t
\t });
更简单的方案是wirking,但如何可以将jSON数组存储在谷歌数据存储使用nodejs
我认为这个问题可以通过重新阅读你正在尝试使用的库的文档来解决,并且如果你检查错误输出(你没有提供) – Nick
@Nick正如我的问题中提到的也是它的400个“错误请求”错误。任何方式都证明这是一个无效的JSON问题,现在修复了git。非常感谢您的时间:) –