Jump to content

"JSON UDF in pure AutoIt" and array count


Go to solution Solved by OJBakker,

Recommended Posts


Hello,

is there any reason why i can't make this example from the german forum output the array size?

#include <JSON.au3>

Example4()

Func Example4()
    ConsoleWrite(@CRLF & @CRLF)
    ConsoleWrite(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" & @CRLF)

    Local $sJSONTest = '[{"_object": "typ","card": "test1"},{"_object": "typ","card": "test2"},{"_object": "typ","card": "test3"},{"_object": "typ","card": "test4"}]'

    Local $o_Object = _JSON_Parse($sJSONTest)
    ConsoleWrite("$o_Object: " & _JSON_Generate($o_Object) & @CRLF)

    $vTmp = _JSON_Get($o_Object, "[1]")
    ConsoleWrite("$vTmp: " & _JSON_Generate($vTmp) & @CRLF)
    ConsoleWrite("$vTmp.Count: " & $vTmp.Count & @CRLF)

    ;Hier würde ich gerne alle enthaltenden ITEMS zählen, in dem Beispiel wären es 4 und in einer Schleife einzeln durchgehen

EndFunc

I can see no value for $vTmp.Count.

Regards

Sascha

Link to comment
Share on other sites

#include <JSON.au3>  ; https://www.autoitscript.com/forum/topic/209502-json-udf-in-pure-autoit/?tab=comments#comment-1512704

Example4()

Func Example4()
    ConsoleWrite(@CRLF & @CRLF)
    ConsoleWrite(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" & @CRLF)

    Local $sJSONTest = '[{"_object": "typ","card": "test1"},{"_object": "typ","card": "test2"},{"_object": "typ","card": "test3"},{"_object": "typ","card": "test4"}]'

    Local $o_Object = _JSON_Parse($sJSONTest)
    ConsoleWrite("$o_Object cnt=" & UBound($o_Object) & @CRLF & @CRLF)

    For $i = 0 To UBound($o_Object, 1) - 1
        $mMap = _JSON_Get($o_Object, "[" & $i & "]")
        ConsoleWrite($i & ") $mMap cnt=" & UBound($mMap) & @CRLF)
        Local $aMapKeys = MapKeys($mMap)
        For $vKey In $aMapKeys
            ConsoleWrite("-- Key: " & $vKey)
            ConsoleWrite(@TAB & "Value: " & $mMap[$vKey])
            ConsoleWrite(@TAB & "Variable Type: " & VarGetType($vKey) & @CRLF)
        Next
        ConsoleWrite("" & @CRLF)
    Next

    ;Hier würde ich gerne alle enthaltenden ITEMS zählen, in dem Beispiel wären es 4 und in einer Schleife einzeln durchgehen

EndFunc   ;==>Example4

if you want more follow the link below and have a look at Reveal hidden contents

 

I know that I know nothing

Link to comment
Share on other sites

3 hours ago, Sascha said:

I can see no value for $vTmp.Count.

In the old version of this udf i used the Scripting.Dictionary to implement a json object.

Since maps are part of the stable releases of AutoIt i switched to the inbuild map datatype.

So in former versions you have to use .Count because a Dictionary is used and in the current versions you have to use Ubound() because objects are implemented as AutoIt-Maps.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...