回到关于mongo和livecode的更多问题,这次是针对mergjson的问题。
情况是这样的:
previous posts中,我问了一些关于如何连接并从查询中获得结果的问题,这些问题在哪里得到了答案。
现在,我将文档从mongo返回到livecode字段中(用于验证目的)。
这是退回的文件:

    { "_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" }

杰森:
[
  { "_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"

09-18 11:52