返回有关Mongo和LiveCode的更多问题,这一次是针对MergJSON的问题。
就是这种情况:在以前的帖子中,我问了一些有关如何连接查询并从查询中获得结果的问题,这些问题在哪里得到了回答。
现在,我在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
此处理程序之后是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
不是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" }
]
请参阅JSON文档
尝试:
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"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句