带有重音的字符串从Mongo到LiveCode

时间:2014-08-14 19:05:59

标签: mongodb character-encoding livecode

自从我在StackOverflow中发帖以来已经有一段时间了。我有一个问题。
当我输入“Secambiaránlosbornes”(请注意重音)时,在LiveCode字段中,正确显示文本,将其写入Mongo集合也工作正常,该字段在文档中保存好,我可以看到它使用Shell,但在将文档检索回LiveCode时, 接收该字段的字段显示:“Secambiarølosbornes”。试图找到我发现字段“结果”的编码是Native的原因。 你能帮忙找到让这些字符串显示正确字符的方法吗?

代码:

on mouseUp
local theMongo, theDB, dbText, theCole, thePreg, theQuerry
put empty into field resul
put "C:\mongodb\bin\mongo.exe localhost:27017/" into theMongo
put "BatGar" into theDB
put "BatRegis"into theCole
put "'" & field F1 & "'" into toFind
put "{"& quote & "_id" & quote & ":" &  toFind & "}" into thePreg
put "; printjson(db.getLastError())" into dbErr
put  ".find(" & thePreg & ");"into theQuerry
put "var c=db."& theCole & theQuerry into dbText
put " while(c.hasNext())" after dbText
put " printjson(c.next())" after dbText
put dbErr after dbText
put theMongo & theDB &&  "--eval"  && quote & dbText & quote  into dbText1
put shell ( quote &dbText1 & quote) into dbResultado
put the number of lines of dbResultado into nro
put line 3 to (nro - 1) of dbResultado into field resul
if field resul is  empty   then
    Answer warning "El Documento NO ha sido encontrado.  El sistema no tiene registrada una Batería con el ID: " &  field F1  with OK
else
    Answer warning "El Documento ha sido encontrado, ID: " &  field F1  with OK
end if

结束mouseUp

1 个答案:

答案 0 :(得分:0)

在LiveCode堆栈中接收Mongo文档时,使用uniDecode函数将UTF-8转换为UTF-16。这样做,你得到正确的重音字符。