错误:无效的JSON对象 [英] Error: Invalid JSON object

查看:419
本文介绍了错误:无效的JSON对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试运行此查询,并继续出现此错误:

I tried to run this query and keep having this error:

install.packages("mongolite")
library(mongolite)

m <- mongo(db = "ionmom")
m6 <- m$aggregate('[{"$unwind":"$cdr"}, {$lookup:{from: "inventory", localField: "_id", foreignField: "_id", as:"inventory"}},{$unwind: "$inventory"}, {"$project":{ "$project": {"cdr.duration": 1, "inventory.wearables.type":1, "inventory.wearables.status":1, "inventory.wearables.battery":1 }}}]')

# Error: Invalid JSON object: [{"$unwind":"$cdr"}, {$lookup:{from: "inventory", localField: "_id", foreignField: "_id", as:"inventory"}},{$unwind: "$inventory"}, {"$project":{ "$project": {"cdr.duration": 1, "inventory.wearables.type":1, "inventory.wearables.status":1, "inventory.wearables.battery":1 }}}]

推荐答案

mongolite在后台使用jsonlite进行JSON解析.如果通过jsonlite::fromJSON()进行查询,则会发现该问题

mongolite uses jsonlite under the hood to do the JSON parsing. If you put your query through jsonlite::fromJSON() you'll see the issue

js <- '[{"$unwind":"$cdr"}, {$lookup:{from: "inventory", localField: "_id", foreignField: "_id", as:"inventory"}},{$unwind: "$inventory"}, {"$project":{ "$project": {"cdr.duration": 1, "inventory.wearables.type":1, "inventory.wearables.status":1, "inventory.wearables.battery":1 }}}]'

jsonlite::fromJSON(js)

# Error: lexical error: invalid char in json text.
#                  [{"$unwind":"$cdr"}, {$lookup:{from: "inventory", loc
#                      (right here) ------^

这是在告诉您JSON结构无效,因为它期望每个字符串都用引号" "

This is telling you the JSON structure is invalid, because it's expecting quotes " " around each string

js <- '[{"$unwind":"$cdr"}, {"$lookup":{"from": "inventory", "localField": "_id", "foreignField": "_id", "as":"inventory"}},{"$unwind": "$inventory"}, {"$project":{ "$project": {"cdr.duration": 1, "inventory.wearables.type":1, "inventory.wearables.status":1, "inventory.wearables.battery":1 }}}]'

m$aggregate(js)

## I don't have your data ...

# Imported 0 records. Simplifying into dataframe...
# data frame with 0 columns and 0 rows

这篇关于错误:无效的JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆