xojo用按钮调用方法

时间:2015-04-21 19:33:06

标签: xojo

我在View方法中使用以下代码来解析JSON文件。方法ContentsOfDictionary接受参数d作为Xojo.Core.Dictionarylevel作为整数,并返回文本。
如果我在动作中使用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

1 个答案:

答案 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