Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/15/2015 in all areas

  1. Introduction JSON (Javascript Object Notation) is a popular data-interchange format and supported by a lot of script languages. On AutoIt, there is already a >JSON UDF written by Gabriel Boehme. It is good but too slow, and not supports unicode and control characters very well. So I write a new one (and of course, fast one as usual). I use a machine code version of JSON parser called "jsmn". jsmn not only supports standard JSON, but also accepts some non-strict JSON string. See below for example. Important Update!! I rename the library from jsmn.au3 to json.au3. All function names are changed, too. Decoding Function Json_Decode($Json) $Json can be a standard or non-standard JSON string. For example, it accepts: { server: example.com port: 80 message: "this looks like a config file" } The most JSON data type will be decoded into corresponding AutoIt variable, including 1D array, string, number, true, false, and null. JSON object will be decoded into "Windows Scripting Dictionary Object" retuned from ObjCreate("Scripting.Dictionary"). AutoIt build-in functions like IsArray, IsBool, etc. can be used to check the returned data type. But for Object and Null, Json_IsObject() and Json_IsNull() should be used. If the input JSON string is invalid, @Error will be set to $JSMN_ERROR_INVAL. And if the input JSON string is not finish (maybe read from stream?), @Error will be set to $JSMN_ERROR_PART. Encoding Function Json_Encode($Data, $Option = 0, $Indent = "\t", $ArraySep = ",\r\n", $ObjectSep = ",\r\n", $ColonSep = ": ") $Data can be a string, number, bool, keyword(default or null), 1D arrry, or "Scripting.Dictionary" COM object. Ptr will be converted to number, Binary will be converted to string in UTF8 encoding. Other unsupported types like 2D array, dllstruct or object will be encoded into null. $Option is bitmask consisting following constant: $JSON_UNESCAPED_ASCII ; Don't escape ascii charcters between chr(1) ~ chr(0x1f) $JSON_UNESCAPED_UNICODE ; Encode multibyte Unicode characters literally $JSON_UNESCAPED_SLASHES ; Don't escape / $JSON_HEX_TAG ; All < and > are converted to \u003C and \u003E $JSON_HEX_AMP ; All &amp;amp;amp;amp;s are converted to \u0026 $JSON_HEX_APOS ; All ' are converted to \u0027 $JSON_HEX_QUOT ; All " are converted to \u0022 $JSON_PRETTY_PRINT ; Use whitespace in returned data to format it $JSON_STRICT_PRINT ; Make sure returned JSON string is RFC4627 compliant $JSON_UNQUOTED_STRING ; Output unquoted string if possible (conflicting with $JSMN_STRICT_PRINT) Most encoding option have the same means like PHP's json_enocde() function. When $JSON_PRETTY_PRINT is set, output format can be change by other 4 parameters ($Indent, $ArraySep, $ObjectSep, and $ColonSep). Because these 4 output format parameters will be checked inside Jsmn_Encode() function, returned string will be always accepted by Jsmn_Decode(). $JSON_UNQUOTED_STRING can be used to output unquoted string that also accetped by Jsmn_Decode(). $JSON_STRICT_PRINT is used to check output format setting and avoid non-standard JSON output. So this option is conflicting with $JSON_UNQUOTED_STRING. Get and Put Functions Json_Put(ByRef $Var, $Notation, $Data, $CheckExists = False) Json_Get(ByRef $Var, $Notation) These functions helps user to access object or array more easily. Both dot notation and square bracket notation can be supported. Json_Put() by default will create non-exists objects and arrays. For example: Local $Obj Json_Put($Obj, ".foo", "foo") Json_Put($Obj, ".bar[0]", "bar") Json_Put($Obj, ".test[1].foo.bar[2].foo.bar", "Test") Local $Test = Json_Get($Obj, '["test"][1]["foo"]["bar"][2]["foo"]["bar"]') ; "Test" Object Help Functions Json_ObjCreate() Json_ObjPut(ByRef $Object, $Key, $Value) Json_ObjGet(ByRef $Object, $Key) Json_ObjDelete(ByRef $Object, $Key) Json_ObjExists(ByRef $Object, $Key) Json_ObjGetCount(ByRef $Object) Json_ObjGetKeys(ByRef $Object) Json_ObjClear(ByRef $Object) These functions are just warps of "Scripting.Dictionary" COM object. You can use these functions if you are not already familiar with it. == Update 2013/05/19 == * Add Jsmn_Encode() option "$JSMN_UNESCAPED_ASCII". Now the default output of Json_Encode() is exactly the same as PHP's json_encode() function (for example, chr(1) will be encoded into u0001). $JSON_UNESCAPED_ASCII ; Don't escape ascii charcters between chr(1) ~ chr(0x1f) == Update 2015/01/08 == * Rename the library from jsmn.au3 to json.au3. All function names are changed, too. * Add Json_Put() and Json_Get() * Add Null support * Using BinaryCall.au3 to loading the machine code. == Update 2018/01/13== (Jos) * Add JsonDump() to list all Json Keys and their values to easily figure out what they are. == Update 2018/10/01== (Jos) * Fixed JsonDump() some fields and values were not showing as discussed here - tnx @TheXman . == Update 2018/10/01b== (Jos) * Added Json_ObjGetItems, Tidied source and fixed au3check warnings - tnx @TheXman . == Update 2018/10/28== (Jos) * Added declaration for $value to avoid au3check warning - tnx @DerPensionist == Update 2018/12/16== (Jos) * Added another declaration for $value to avoid au3check warning and updated the version at the top - tnx @maniootek == Update 2018/12/29== (Jos) * Changed Json_ObjGet() and Json_ObjExists() to allow for multilevel object in string. == Update 2019/01/17== (Jos) * Added support for DOT notation in JSON functions. == Update 2019/07/15== (Jos) * Added support for reading keys with a dot inside when using a dot as separator (updated) == Update 2021/11/18== (TheXman) * Update details in below post: == Update 2021/11/20== (TheXman) * Minor RegEx update, no change to the functionality or result._Json(2021.11.20).zip
    1 point
  2. LarsJ

    resize controls bar

    I have not added code for any of these cases. Just normal resize. I'll take a closer look tomorrow.
    1 point
  3. Don't think this is 100% correct. I would have said that a "newline" is sometime CRLF and sometimes either LF or CR. On this topic in general: it feels like some people have way too much time on their hands to come up with these kind of proposals and have this lengthy discussion about it. These design decision where made a long time ago and honestly fail to see the benefit of any change other than when the goal is to confuse people. .Jos
    1 point
  4. You never lose when you learn something.
    1 point
  5. TheCrimsonCrusader, Use a marquee progress bar - that is why it exists: #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> $hGUI = GUICreate("Test", 500, 500) GUICtrlCreateProgress(10, 10, 400, 20, $PBS_MARQUEE) GUICtrlSendMsg(-1, $PBM_SETMARQUEE, True, 50) ; final parameter is update time in ms GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEndM23
    1 point
  6. Every AutoIt macro is there to save you from writing a bunch of lines yourself to get the correct information, you can list them all one by one if you wish to but it wont change it. With $CommandLineRaw, you'd be replacing $ with @ and probably making some internal call which is not needed. I've tried, but still cannot see a single valid reason to have it.
    1 point
  7. Xenobiologist's regex works, but must be enclosed in a duplicate subpattern group : #include <array.au3> $pattern = '(?|%(\w+)%|,\s*(\w+))' $str = "%abcd% = Section, hardwareID_1, hardwareID_2, ..... ,HardwareID_n" $array = StringRegExp($str, $pattern, 3) _ArrayDisplay($array)
    1 point
  8. Or do it the right way and declare both variables, and then set the values to them inside the switch statement. Func _DoStuff($iParm) Local $sVar1, $sVar2 Switch $iParm Case 1 $sVar1 = "w" $sVar2 = "x" ; do stuff Return Case 2 $sVar1 = "y" $sVar2 = "z" ; do stuff Return EndSwitch EndFuncConditionally declaring variables is a bad idea.
    1 point
  9. The variables will be defined when AutoIt processes the Local statement. You could check after EndSwitch. If IsDeclared("sVar1") Then ConsoleWrite("$sVar1 is declared") If IsDeclared("sVar3") Then ConsoleWrite("$sVar3 is declared")
    1 point
  10. There is a FTP UDF distributed along with AutoIt, Check the help file
    1 point
  11. silly question - have you tried the FTP UDF that ships with AutoIt, or the SFTP UDF from the Example Scripts forum?
    1 point
  12. Alt is held the entire time, so escape never gets pressed. Alt + escape does instead.
    1 point
  13. If you have the latest SciTE installed try pressing {CTRL} & {T} and it should correct the problem. Works fine now. Link to the latest editor. https://www.autoitscript.com/site/autoit-script-editor/downloads/
    1 point
  14. Thanks - I'm not interested in the string - I just got it off the internet as an example of json http://mtgjson.com/ silly me I didn't even think of what it was. Sorry everyone.
    1 point
  15. Attached are some 80 UDFs for Rich Edit. They have all been tested fairly extensively. The .zip file includes Notes.rtf. The included Example.au3 reads Notes.rtf. Many of the functions are based on the ones Prog@ndy collected from the forums and the ones he wrote. Suggestions for improvements are welcome. If I failed to credit an author of some code, please advise. Without you guys, I wouldn't have advanced as far as I have. ...chris Version 0.1 attached Version 0.3 attached Version 0.4 attached Version 0.5 attached - now 96 functions
    1 point
  16. Tec

    Joining domain...

    This works for me. Const $JOIN_DOMAIN = 1 Const $ACCT_CREATE = 2 Const $ACCT_DELETE = 4 Const $WIN9X_UPGRADE = 16 Const $DOMAIN_JOIN_IF_JOINED = 32 Const $JOIN_UNSECURE = 64 Const $MACHINE_PASSWORD_PASSED = 128 Const $DEFERRED_SPN_SET = 256 Const $INSTALL_INVOCATION = 262144 Const $DOMAIN = "'DOMAIN.LOCAL" ;change Domain Const $ADMINKENNWORT = "ADMINPASSWORD" ;change PW Const $ADMIN = "Administrator" Const $COMPUTER = @ComputerName $objComputer = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\\" & $COMPUTER & "\root\cimv2:Win32_ComputerSystem.Name='" & $COMPUTER & "'") $Ergebnis = $objComputer.JoinDomainOrWorkGroup($DOMAIN, $ADMINKENNWORT, $DOMAIN & "\" & $ADMIN, "", $JOIN_DOMAIN + $ACCT_CREATE) If ($Ergebnis <> 0) Then MsgBox(0, "Fehler beim beitritt in die Domain", $COMPUTER & " Fehler code: " & $Ergebnis ) EndIf
    1 point
×
×
  • Create New...