Sascha Posted March 11, 2023 Share Posted March 11, 2023 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 More sharing options...
Solution OJBakker Posted March 11, 2023 Solution Share Posted March 11, 2023 The variable $vTmp is of type Map, so you have to use Ubound($vTmp). Link to comment Share on other sites More sharing options...
ioa747 Posted March 11, 2023 Share Posted March 11, 2023 #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 More sharing options...
AspirinJunkie Posted March 11, 2023 Share Posted March 11, 2023 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 More sharing options...
Sascha Posted March 17, 2023 Author Share Posted March 17, 2023 I got it working now. Thank you for your help. Link to comment Share on other sites More sharing options...
Graeme Posted June 3 Share Posted June 3 I want to analyse Thunderbird json files and I just started using this UDF. However when I finally ran the program I had a weird error. When I run my program uncompiled everything works but as soon as I compile the program and run it, it crashes on this line: Local $o_Current[] It says array badly formatted. Does this mean that the JSON file is not correctly formatted? But why does it work uncompiled. I don't understand the code enough to figure out what is happening. Any help gratefully received. Link to comment Share on other sites More sharing options...
paw Posted June 3 Share Posted June 3 That's how you declare a Map, update to the latest AutoIt version. AspirinJunkie 1 Link to comment Share on other sites More sharing options...
Graeme Posted June 3 Share Posted June 3 (edited) Sorry to be dumb, but I thought I was on the latest version (3.3.16.1). Also that wouldn't explain why it crashed when compiled and not when run precompile. In addition, I've compiled a short script that just does the _JSON_Parse and it doesn't crash. I just can't make sense of it at all. I don't know why that line would crash. Edited June 3 by Graeme Link to comment Share on other sites More sharing options...
Nine Posted June 3 Share Posted June 3 Maybe posting a small reproducible script with the json file would help us ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
argumentum Posted June 3 Share Posted June 3 3 hours ago, Graeme said: When I run my program uncompiled Maybe a x64 vs. x86 ?, Run in one but complied the other ? Also for older versions, there is a "JSON_Dictionary.au3" that does the map/dictionary, if memory serves. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Graeme Posted June 5 Share Posted June 5 It's true that it may be running in x86 but compiled in x64. How would that make it crash and if so how could I get around it. It's true that the test script I mentioned was in x86 and the script that crashed was in x64..... The JSON file was the preferences file for Edge. The test script: $ScriptDrive = "U:\" If FileExists($ScriptDrive & "Settings\Edge\Default\Preferences") Then Dim $Fields[6] = ["local_browser_data_share.enabled","download.default_directory","savefile.default_directory", _ "third_party_search.consented","user_experience_metrics.personalization_data_consent_enabled","ntp.enable_prerender"] ;$Fields are the values that we want to verify $Changed = False $Data = FileRead($ScriptDrive & "Settings\Edge\Default\Preferences") $oObject = _JSON_Parse($Data) For $R = 0 To UBound($Fields) - 1 $Setting = _JSON_Get($oObject, "." & $Fields[$R]) If $R > 0 and $R < 3 Then If MsgBox(1,$Fields[$R],$Setting) = 2 Then Exit EndIf If StringInStr($Fields[$R],"Default_directory") = 0 Then If $Setting <> "False" Then _JSON_addChangeDelete($oObject,$Fields[$R],"False") $Changed = True EndIf Else If StringLeft($Setting,3) <> $ScriptDrive Then _JSON_addChangeDelete($oObject,$Fields[$R],$ScriptDrive & "Downloads") $Changed = True EndIf EndIf Next If $Changed Then; Update the Preferences File MsgBox(0,"","Changed " & _JSON_Get($oObject,"." & $Fields[1])) $success = 1 $hFile = FileOpen($ScriptDrive & "Settings\Edge\Default\Preferences",2) $result = FileWriteLine($hFile,_JSON_GenerateCompact($oObject)) If $result <> $success Then MsgBox(0,"ERROR","The file write didn't happen!" & @CRLF & FileGetAttrib($ScriptDrive & "Settings\Edge\Default\Preferences")) FileClose($hFile) MsgBox(0,"",$result) EndIf EndIf Link to comment Share on other sites More sharing options...
Nine Posted June 5 Share Posted June 5 It does not crash on me. Compiled in x64, works fine. So there is something buggy in your side. Maybe AV (look at log) ? Put some tracing in your script to see where it crashed (on which exact statement), see if it is always on the same line... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Graeme Posted June 5 Share Posted June 5 (edited) OK so I compiled the above script as a3x x64 and ran it with the AutoIT3.exe as normal and it crashed with the same error message. I inserted a couple of msgboxes into the UDF to confirm that the line when this happens is Local $o_Current[] I tried compiling as x86 and got the same error message Edited June 5 by Graeme Link to comment Share on other sites More sharing options...
Nine Posted June 5 Share Posted June 5 Hey, that line is not even in the script you provided ! So maybe you should think of making a real test case of your script that is runable to us and will show the error. Until then I am out of here. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Graeme Posted June 5 Share Posted June 5 That line is in the UDF... That's why I'm asking how this could be fixed... It looks like there's a problem with the UDF. That the script runs into. Link to comment Share on other sites More sharing options...
ioa747 Posted June 5 Share Posted June 5 (edited) Graeme you are not giving us all your details. E.G. since you're using JSON.au3, there will be a #include <JSON.au3> command somewhere. Even though I don't see it, I place it, and despite this I reach the maximum of 550 rows. In the message you posted, it says that an error was found in the 3659 row (which means that there are more) So you have to show us the whole script, if you want us to take an edge as the console content would also help to understand what version of AutoIt you are running, since as mentioned above the "Local $o_Current[]" you provide above refers to a Map variable, which is available in the latest AutoIt Version 3.3 .16.1 run it next, what does it say? ConsoleWrite("AutoItVersion:" & @AutoItVersion & @CRLF) 1 hour ago, Graeme said: It looks like there's a problem with the UDF incidentally in the udf folder autoit-json-udf-master there is the example JSON-Test.au3. You tried it ? does it work for you ? for me it works fine Edited June 5 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
argumentum Posted June 5 Share Posted June 5 (edited) 1 hour ago, Graeme said: It looks like there's a problem with the UDF I've run into problems with this UDF on a project. And because I don't personally know anything thoroughly, I just chose another UDF ( don't remember which UDF ). Edited June 5 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Graeme Posted June 14 Share Posted June 14 OK. I got a bit involved with other things. Here is the parred down script with all the stuff that was commented out before, gone. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile_type=a3x #AutoIt3Wrapper_Outfile=U:\Documents\z Graeme and Helen\QA files\QuickAccess3.0\TestJSON.a3x #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #comments-start Title : Test Author : Graeme Desc : Test JSON Udf #comments-end #include <json.au3> $ScriptDrive = "U:\" If FileExists($ScriptDrive & "Settings\Edge\Default\Preferences") Then Dim $Fields[6] = ["local_browser_data_share.enabled","download.default_directory","savefile.default_directory", _ "third_party_search.consented","user_experience_metrics.personalization_data_consent_enabled","ntp.enable_prerender"] ;$Fields are the values that we want to verify $Changed = False $Data = FileRead($ScriptDrive & "Settings\Edge\Default\Preferences") $oObject = _JSON_Parse($Data) For $R = 0 To UBound($Fields) - 1 $Setting = _JSON_Get($oObject, "." & $Fields[$R]) If $R > 0 and $R < 3 Then If MsgBox(1,$Fields[$R],$Setting) = 2 Then Exit EndIf If StringInStr($Fields[$R],"Default_directory") = 0 Then If $Setting <> "False" Then _JSON_addChangeDelete($oObject,$Fields[$R],"False") $Changed = True EndIf Else If StringLeft($Setting,3) <> $ScriptDrive Then _JSON_addChangeDelete($oObject,$Fields[$R],$ScriptDrive & "Downloads") $Changed = True EndIf EndIf Next If $Changed Then; Update the Preferences File MsgBox(0,"","Changed " & _JSON_Get($oObject,"." & $Fields[1])) $success = 1 $hFile = FileOpen($ScriptDrive & "Settings\Edge\Default\Preferences",2) $result = FileWriteLine($hFile,_JSON_GenerateCompact($oObject)) If $result <> $success Then MsgBox(0,"ERROR","The file write didn't happen!" & @CRLF & FileGetAttrib($ScriptDrive & "Settings\Edge\Default\Preferences")) FileClose($hFile) MsgBox(0,"",$result) EndIf EndIf As I said I compiled this as an a3x file and ran it with this line.. MsgBox(0,"",Run('C:\Program Files\Qa\Autoit3.exe "U:\Documents\z Graeme and Helen\QA Files\QuickAccess3.0\TestJSON.a3x"')) It ran and I got this error. I inserted msgbox lines before and after the line that had always given issues like this in the UDF if MsgBox(1,"","Before line" & @CRLF & $s_String) = 2 Then Exit Local $o_Current[] If MsgBox(1,"","After line") = 2 Then Exit I got the first msgbox with the contents of the preferences file as expected then this. Here is the console output to show versions of AutoIT3 etc >"C:\Program Files (x86)\AutoIT3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIT3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "U:\Documents\z Graeme and Helen\QA files\QuickAccess3.0\Test.au3" /UserParams +>09:52:58 Starting AutoIt3Wrapper (21.316.1639.1) from:SciTE.exe (4.4.6.0) Keyboard:00000809 OS:WIN_11/2009 CPU:X64 OS:X64 Environment(Language:0809) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper >Running AU3Check (3.3.16.1) from:C:\Program Files (x86)\AutoIt3 input:U:\Documents\z Graeme and Helen\QA files\QuickAccess3.0\Test.au3 +>09:52:58 AU3Check ended.rc:0 >Running:(3.3.16.1):C:\Program Files (x86)\AutoIt3\autoit3.exe "U:\Documents\z Graeme and Helen\QA files\QuickAccess3.0\Test.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. Link to comment Share on other sites More sharing options...
Graeme Posted June 14 Share Posted June 14 (edited) I may have found the issue. I decided to run the file with a different executable, one that I have recently compiled and this worked. So the problem seems to be in AutoIT3.exe handling Maps..... MsgBox(0,"",Run('U:\Settings\QuickAccess\OpenWebLink64.exe "U:\Documents\z Graeme and Helen\QA Files\QuickAccess3.0\TestJSON.a3x"')) I don't know if this means that something in AutoIT3.exe needs to be updated but I can't use that because the AutoIT3.exe is already deployed over how ever many of the company are using the program - I'll have to move away from using AutoIt3.exe to run a3x files as I see it. Edited June 14 by Graeme Link to comment Share on other sites More sharing options...
ioa747 Posted June 14 Share Posted June 14 (edited) 15 hours ago, Graeme said: MsgBox(0,"",Run('C:\Program Files\Qa\Autoit3.exe "U:\Documents\z Graeme and Helen\QA Files\QuickAccess3.0\TestJSON.a3x"')) C:\Program Files\Qa\Autoit3.exe the address here does not match the one on the console C:\Program Files (x86)\AutoIt3 Edit: Start with something simple first to make sure everything works. And step by step you fill in the rest I changed some settings from $Fields[6] because I couldn't find them (at least to me) #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile_type=a3x #AutoIt3Wrapper_Outfile=U:\Documents\z Graeme and Helen\QA files\QuickAccess3.0\TestJSON.a3x #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <json.au3> _TestJSON() Func _TestJSON() Local $ScriptDrive = "U:\" If FileExists($ScriptDrive & "Settings\Edge\Default\Preferences") Then Dim $Fields[6] = [".account_info[0].edge_account_first_name", ".account_info[0].email", ".savefile.default_directory", _ ".third_party_search.consented", ".user_experience_metrics.personalization_data_consent_enabled", ".web_app.system_installed_label_updated"] Local $Data = FileRead($ScriptDrive & "Settings\Edge\Default\Preferences") Local $oObject = _JSON_Parse($Data) Local $Setting = "" For $R = 0 To UBound($Fields) - 1 $Setting &= $R & ") " & _JSON_Get($oObject, $Fields[$R]) & @CRLF Next MsgBox(0, "JSON Setting:", $Setting) EndIf EndFunc ;==>_TestJSON Try it first without compiling it. Edited June 15 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now