返回有关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" }
我现在想要什么,而且无法工作就是这样,我的堆栈有一个按钮脚本我有一个鼠标处理程序:
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
此处理程序之后是Decode和Encode函数。
运行此脚本时出现错误:
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
答案 0 :(得分:2)
不是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" }
]
尝试:
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"