1

I have the code below in a View method to parse JSON files. The method ContentsOfDictionary accepts the parameters d as Xojo.Core.Dictionary and level as an integer, and returns text.
If I use ContentsOfDictionary in an action button, I get this error:

error: Not Enough arguments: got 0, expected at least 1

Here is a link to the test file I am using.
How do I call the method 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
ASCIIThenANSI
  • 865
  • 1
  • 9
  • 27
johnnyB
  • 165
  • 1
  • 12

1 Answers1

2

UPDATE: None of the below applies as @johnnyB's example was of the ContentsOfDictionary function and should not have been trying to access the JSON data but just working on the supplied Dictionary. There is a link to the fixed test project in the comments below.


It's failing because you're not satisfying the parameter types of any of ContentsOfDictionary's signatures.

entry.Value is of type Auto, so before calling ContentsOfDictionary you need to copy entry.Value into a Dictionary and pass that in to the function instead.

For example...

    ...
    case "Dictionary"
        dim d as new Xojo.Core.Dictionary = entry.Value
        t = t  + kEOL + ContentsOfDictionary( d, level + 1 )
end select
ianmjones
  • 3,395
  • 1
  • 25
  • 26
  • your answer is confuse me. copy the entry.value from where?there is only one button with empty action and one textfield to show the data.How will call above method from button can you give me a example how to ? – johnnyB Apr 21 '15 at 23:39
  • I've added a little example of assigning the Auto to a Dictionary. – ianmjones Apr 22 '15 at 00:01
  • `dim d as new Xojo.Core.Dictionary ` exist on ContentsOfDictionary parameters so this is error in code,and the example is for the method,no for the action.thee is a link with the test file please check it – johnnyB Apr 22 '15 at 00:11
  • It wasn't clear from your above example that the code was from inside ContentsOfDictionary, it would have helped as your test project showed you were trying to access variables that don't exist. Your test project wasn't even trying to use ContentsOfDictionary. Here's a fixed version of your test project that runs (and doesn't need the extra Dictionary assign) https://dl.dropboxusercontent.com/u/6199282/test.xojo_binary_project%202.zip – ianmjones Apr 22 '15 at 01:04