gpt4 book ai didi

json - 错误 : Invalid JSON object

转载 作者:可可西里 更新时间:2023-11-01 10:02:39 24 4
gpt4 key购买 nike

我尝试运行此查询并一直出现此错误:

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() 进行查询,您将看到问题

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 结构无效,因为它需要在每个字符串周围加上引号 ""

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 - 错误 : Invalid JSON object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42351682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com