我在View
方法中使用以下代码来解析JSON文件。方法ContentsOfDictionary
接受参数d
作为Xojo.Core.Dictionary
和level
作为整数,并返回文本。
如果我在动作中使用ContentsOfDictionary
按钮,我收到此错误:
error: Not Enough arguments: got 0, expected at least 1
Here is a link to the test file I am using.
如何调用方法ContentsOfDictionary
?
dim dict as Xojo.Core.Dictionary = Xojo.Data.ParseJSON (kJsonData)
const kEOL = &u0A
dim indent as text
for i as integer = 1 to level
indent = indent + " "
next
dim t as text
for each entry as Xojo.Core.DictionaryEntry in dict
t = t + indent + entry.Key + " "
if Xojo.Introspection.GetType( entry.Value ) is nil then
t = t + "nil" + kEOL
else
select case Xojo.Introspection.GetType( entry.Value ).Name
case "Boolean"
t = t + if( entry.Value, "true", "false" ) + kEOL
case "Text"
t = t + entry.Value + kEOL
case "Int32", "Int64"
//
// You get the idea
//
case "Dictionary"
t = t + kEOL + ContentsOfDictionary( entry.Value, level + 1 )
end select
end if
next
return t
答案 0 :(得分:2)
更新:以下都不适用,因为@ johnnyB&#39}的示例属于ContentsOfDictionary
函数,并且不应该尝试访问JSON数据,而只是处理提供的Dictionary
。在下面的评论中有一个固定测试项目的链接。
它失败了,因为您不满足任何ContentsOfDictionary
签名的参数类型。
entry.Value
的类型为Auto
,因此在调用ContentsOfDictionary
之前,您需要将entry.Value
复制到Dictionary
并将其传递给该函数。
例如......
...
case "Dictionary"
dim d as new Xojo.Core.Dictionary = entry.Value
t = t + kEOL + ContentsOfDictionary( d, level + 1 )
end select