gpt4 book ai didi

mongodb - Mongo LiveCode MergJSON 无法解码文档

转载 作者:可可西里 更新时间:2023-11-01 10:31:46 25 4
gpt4 key购买 nike

返回有关 Mongo 和 LiveCode 的更多问题,这次是针对 MergJSON 的特定问题。

情况是这样的: 在 previous posts我问了一些关于如何连接和从查询中获得结果的问题,这些问题都得到了回答。

现在我在 LiveCode 字段中有从 Mongo 返回的文档(用于验证目的)。

这是返回的文件:

    { "_id" : "001003", "nombre" : "Pedro" }
{ "_id" : "001004", "nombre" : "Alejandro" }
{ "_id" : "001005", "nombre" : "Mario" }
{ "_id" : "001001", "nombre" : "Javier" }
{ "_id" : "001002", "nombre" : "Andrecillo" }

我现在想要的,但无法工作的是,我的堆栈有一个按钮脚本,我有一个 mouseup 处理程序:

on mouseUp
local dbText, dbResultado
set the hideConsoleWindows to true
put "var c=db.nueva.find();" into dbText
put " while(c.hasNext())" after dbText
put " printjson(c.next())" after dbText
put shell("C:\mongodb\bin\mongo.exe --eval" && quote & dbText & quote) into dbResultado
put line 3 to -1 of dbResultado into pJSON
put pJSON into field "A" -- just to see what Mongo is returning after eliminating line 1 and 2 of dbResultado
put JSONToArray(pJSON) into tArray
put tArray["nombre"] into fld "B"
end mouseUp

此处理程序之后是解码和编码功能。

运行此脚本时出现错误:

     executing at 10:15:18 AM
Type could not decode JSON: end of file expected near '{'
Object Mejoraddo
Line repeat for each line tKey in mergJSONDecode(pJSON,"tArray")
Hint could not decode JSON: end of file expected near '{'

在函数 JSONToArray pJSON 的这一行中:

     repeat for each line tKey in mergJSONDecode(pJSON,"tArray")

我几乎可以肯定我错过了一个简单的步骤或监督了一些明显的事情。拜托,如果您需要一些说明,我会尝试更好地解释这一点,在此先感谢您,

Javier

最佳答案

不是 JSON:

{ "_id" : "001003", "nombre" : "Pedro" }
{ "_id" : "001004", "nombre" : "Alejandro" }
{ "_id" : "001005", "nombre" : "Mario" }
{ "_id" : "001001", "nombre" : "Javier" }
{ "_id" : "001002", "nombre" : "Andrecillo" }

JSON:

[
{ "_id" : "001003", "nombre" : "Pedro" },
{ "_id" : "001004", "nombre" : "Alejandro" },
{ "_id" : "001005", "nombre" : "Mario" },
{ "_id" : "001001", "nombre" : "Javier" },
{ "_id" : "001002", "nombre" : "Andrecillo" }
]

参见 the JSON docs

尝试:

local tIndex = 1
repeat for each line tJSON in line 3 to -1 of dbResultado
put JSONToArray(tJSON) into tArray[tIndex]
add 1 to tIndex
end repeat
put tArray[1]["nombre"] into fld "B"

关于mongodb - Mongo LiveCode MergJSON 无法解码文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22508972/

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