Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

JSON UDF


  • Please log in to reply
18 replies to this topic

#1 BAM5

BAM5

    Wayfarer

  • Active Members
  • Pip
  • 90 posts

Posted 08 October 2009 - 04:55 AM

Well today I was making a program and wanted to store a few parameters and variables and whatnot. It's been ages since I've worked with AutoIt (no reason why, just have been doing other type of developing) and thought to use JSON since I use it quite a bit to transfer and store information with javascript. So I get on the forums to find that no one has made a JSON UDF! "Well what the heck is this?!" I think to myself. So I decided to sit down for the last 3 or 4 hours to create one. So without further ado, I give to you, the JSON UDF.

Updated to V0.3 (Thanks for the SRE wraithdu)

JSON Example:
Dim $array1[2] = ["test1", False], $array[6] = [1.3456, 2, Binary(0xFFFFFF), False, 't,e"st', $array1] _ArrayDisplay($array) $JSONString = _ToJSONString($array) MsgBox(0, "JSONString", $JSONString) $ArrayAfterJSON = _FromJSONString($JSONString) _ArrayDisplay($ArrayAfterJSON) $array1fromJSON = $ArrayAfterJSON[5] If Not $array1fromJSON[1] Then     MsgBox(0, "", $array1fromJSON[0]) EndIf


JSON UDF:
AutoIt         
; =================================================================== ; JSON UDF's ; v0.3 ; ; By: BAM5 ; Last Updated: 10/07/2009 ; Tested with AutoIt Version 3.3.0.0 ; Extra requirements: Nothing! ; ; A set of functions that allow you to encode and decode JSON Strings ; ; Thanks to wraithdu for setting me up with some SRE. It really made ; the script a lot less messy. ; ; Comments: ;           Unfortunately I have no idea how to encode or even detect ;       multi-dimensional arrays. I wish multi-dimensional arrays in ;       Autoit were more like javascript where $array[0] would point ;       to another array so accessing the array in the array would be ;       coded like this $array[0][0]. But that's more OOP which AIT ;       hasn't really gotten into. ; ;           In order to access arrays in other arrays you must first ;       point a variable to the embeded array. Example: ; ;               Dim $EmbededArray[1]=["Look I work!"] ;               Dim $ArrayWithArrayInside[2]=[$EmbededArray, "extra"] ;               $array = $ArrayWithArrayInside[0] ;               MsgBox(0, "Hooray!", $array[0]) ; ;           With the way Javascript works it would be: ; ;               Dim $EmbededArray[1]=["Look I work!"] ;               Dim $ArrayWithArrayInside[2]=[$EmbededArray, "extra"] ;               MsgBox(0, "Hooray!", $ArrayWithArrayInside[0][0]) ; ;           Which is why JSON is more sensible in Javascript and other ;       languages. ; ; Main functions: ; _toJSONString - Encodes a object to a JSON String ; _fromJSONString - Creates a object from a JSON String ; =================================================================== #include <Array.au3> #include-once ; =================================================================== ; _ToJSONString($obj) ; ; Goes through an object you give it- being an array or string or ; other- and turns it into a JSON String which you can send to ; servers or save to a text file to recall information later. ; ; Parameters: ;   $obj - IN - Object to be turnd into a JSON String ; Returns: ;   JSON String or false on failure ; Errors: ;   @error = 1 - Unknown type of variable inputed ; =================================================================== Func _ToJSONString($obj)     If IsArray($obj) Then         $returnString = "["         For $object In $obj             $returnString &= _ToJSONString($object) & ","         Next         $returnString = StringLeft($returnString, StringLen($returnString) - 1)         $returnString &= "]"     ElseIf IsFloat($obj) Or IsInt($obj) Or IsBinary($obj) Then         $returnString = String($obj)     ElseIf IsBool($obj) Then         If $obj Then             $returnString = "true"         Else             $returnString = "false"         EndIf     ElseIf IsString($obj) Then         $returnString = '"' & StringReplace(StringReplace(String($obj), '"', '\"'), ',', '\,') & '"'     Else         SetError(1)         Return (False)     EndIf     Return ($returnString) EndFunc   ;==>_toJSONString ; =================================================================== ; _FromJSONString($str) ; ; Takes a JSON String and decodes it into program objects such as ; arrays and numbers and strings and bools. ; ; Parameters: ;   $str - IN - The JSON String to decode into objects ; Returns: ;   A object decoded from a JSON String or False on error ; Errors ;   @error = 1 - Syntax error in the JSON String or unknown variable ;   Also, if there is an error in decoding part of the string such as ;       a variable or a array, this function will replace the variable ;       or array with a string explaining the error. ; =================================================================== Func _FromJSONString($str)     If StringLeft($str, 1) = '"' And StringRight($str, 1) = '"' And Not (StringRight($str, 2) = '\"') Then         $obj = StringReplace(StringReplace(_StringRemoveFirstLastChar($str, '"'), '\"', '"'), '\,', ',')     ElseIf $str = "true" Then         $obj = True     ElseIf $str = "false" Then         $obj = False     ElseIf StringLeft($str, 2) = "0x" Then         $obj = Binary($str)     ElseIf StringIsInt($str) Then         $obj = Int($str)     ElseIf StringIsFloat($str) Then         $obj = Number($str)     ElseIf StringLeft($str, 1) = '[' And StringRight($str, 1) = ']' Then         $str = StringTrimLeft($str, 1)         $str = StringTrimRight($str, 1)         $ufelems = StringRegExp($str, "(\[.*?\]|.*?[^\\])(?:,|\z)", 3)         Dim $obj[1]         For $elem In $ufelems             $insObj = _FromJSONString($elem)             If $insObj = False And @error = 1 Then $insObj = 'Error in syntax of piece of JSONString: "' & $elem & '"'             _ArrayAdd($obj, $insObj)         Next         _ArrayDelete($obj, 0)     Else         SetError(1)         Return (False)     EndIf     Return ($obj) EndFunc   ;==>_fromJSONString ; =================================================================== ; _StringRemoveFirstLastChar($str, $char[, $firstCount=1[, $lastCount=1]]) ; ; Removes characters matching $char from the beginning and end of a string ; ; Parameters: ;   $str - IN - String to search search modify and return ;   $char - IN - Character to find and delete in $str ;   $firstCount - OPTIONAL IN - How many to delete from the beginning ;   $lastCount - OPTIONAL IN - How many to delete from the end ; Returns: ;   Modified string ; Remarks: ;   Could probably be easily turned into a replace function ;                   (But I'm too lazy :P ) ; =================================================================== Func _StringRemoveFirstLastChar($str, $char, $firstCount = 1, $lastCount = 1)     $returnString = ""     $splited = StringSplit($str, '"', 2)     $count = 1     $lastCount = UBound($splited) - $lastCount     For $split In $splited         $returnString &= $split         If $count > $firstCount And $count < $lastCount Then $returnString &= '"'         $count += 1     Next     Return ($returnString) EndFunc   ;==>_StringRemoveFirstLastChar


Unfortunately, arrays in autoit don't quite work like arrays in other programming languages. In order to modify array elements that are nested in another array you must first make a variable point to the nested array.
Dim $EmbededArray[1]=["Look I work!"] Dim $ArrayWithArrayInside[2]=[$EmbededArray, "extra"] $array = $ArrayWithArrayInside[0] MsgBox(0, "Hooray!", $array[0])


For those of you who are unaware of what JSON is and what it does exactly, here is a brief description.

JSON stands for Javascript Object Notation. Well why is javascript in Autoit you ask? Well the name isn't everything. JSON allows you to store complex objects like arrays in a human readable string form. This means you can save arrays to text files and send them over the internet. This is known as serialization, but not all serializing forms can be read (easily) by humans.

Attached Files

  • Attached File  JSON.au3   5.53KB   651 downloads

Edited by bam5, 09 October 2009 - 04:36 AM.








#2 JRowe

JRowe

    Chasing the white rabbits

  • Active Members
  • PipPipPipPipPipPip
  • 1,765 posts

Posted 08 October 2009 - 06:15 AM

"Well what the heck is this?!"

Beautiful is what it is, dammit. Just beautiful.

Nice work, man, simple and clean. Shouldn't be much work at all to integrate with the various javascript frameworks that make extensive or integral use of JSON (mootools, et al.) Thanks!

#3 wraithdu

wraithdu

    this noise inside my head

  • MVPs
  • 2,412 posts

Posted 08 October 2009 - 07:55 PM

Try this SRE in your _FromJSONString() function:
$ufelems = StringRegExp($str, "(\[.*?\]|.*?[^\\])(?:,|\z)", 3)

This could replace that complex string array parsing.

Edited by wraithdu, 08 October 2009 - 07:56 PM.


#4 Minikori

Minikori

    I like to cut people in my freetime

  • Active Members
  • PipPipPipPipPipPip
  • 527 posts

Posted 08 October 2009 - 09:17 PM

AutoIT can do $array[0][0]...
EDIT: And also, your _StringRemoveFirstLastChar() could be much simpler if you use StringTrimLeft() and StringTrimRight()

Edited by Minikori, 08 October 2009 - 09:18 PM.

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.

They already have a punishment system for abuse.

... and his his name is Valik.

www.minikori.com

#5 Manadar

Manadar

         

  • MVPs
  • 10,845 posts

Posted 08 October 2009 - 09:23 PM

Posted Image

#6 wraithdu

wraithdu

    this noise inside my head

  • MVPs
  • 2,412 posts

Posted 08 October 2009 - 10:30 PM

AutoIT can do $array[0][0]...

You don't understand, he's talking about storing an array as an array element, then accessing that data:
Dim $array1[1] = ["element"] Dim $array2[1] = [$array1] ;this will not work ConsoleWrite($array1[0][0] & @CRLF) ;this will $aTemp = $array2[0] ConsoleWrite($aTemp[0] & @CRLF)


#7 JRowe

JRowe

    Chasing the white rabbits

  • Active Members
  • PipPipPipPipPipPip
  • 1,765 posts

Posted 08 October 2009 - 11:15 PM

Yes. Arrays in arrays need to be explicitly called, because of the capability for multi-dimensional arrays. There's no way for the interpreter to tell the difference between a 2 dimensional array and an attempt to access the first element of an array stored at in the element.

Both are expressed as $array[0][0], which makes the choice between accessing single dimensional arrays containing other arrays, or having multi dimensional arrays. I don't think both are possible (at least without an insane amount of overhead.)

#8 BAM5

BAM5

    Wayfarer

  • Active Members
  • Pip
  • 90 posts

Posted 09 October 2009 - 01:16 AM

Wow, thanks for the feedback everyone! Now that I think about it, I wonder if I can just declare a multi-dimensional array and then make "arrays" in the second dimension. But then that would be confusing to make into a JSON String because I have no idea how or if I can detect multi-dimentionals in Autoit. Wraithdu, thanks for the SRE, I'll put it in there and figure out how it works. But if anyone knows how to detect multi-dimension arrays I'd greatly appreciate it if you shared this knowledge with me! :)

#9 JRowe

JRowe

    Chasing the white rabbits

  • Active Members
  • PipPipPipPipPipPip
  • 1,765 posts

Posted 09 October 2009 - 01:27 AM

Something like this:
For $i = 0 To Ubound($arrayToTest) -1 Step 1 $test = $arrayToTest[$i] If IsArray($test) Then MsgBox(0,"Detected An Array", "The element at position: " & $i & " is an array") EndIf Next


IsArray can determine if something is an array, so you'd loop through the elements, recursively for multi-dimensional arrays.

#10 wraithdu

wraithdu

    this noise inside my head

  • MVPs
  • 2,412 posts

Posted 09 October 2009 - 03:50 AM

I'll put it in there and figure out how it works.

This will do it:
AutoIt         
Func _FromJSONString($str)     If StringLeft($str, 1) = '"' And StringRight($str, 1) = '"' And Not (StringRight($str, 2) = '\"') Then         $obj = StringReplace(StringReplace(_StringRemoveFirstLastChar($str, '"'), '\"', '"'), '\,', ',')     ElseIf $str = "true" Then         $obj = True     ElseIf $str = "false" Then         $obj = False     ElseIf StringLeft($str, 2) = "0x" Then         $obj = Binary($str)     ElseIf StringIsInt($str) Then         $obj = Int($str)     ElseIf StringIsFloat($str) Then         $obj = Number($str)     ElseIf StringLeft($str, 1) = '[' And StringRight($str, 1) = ']' Then         $str = StringTrimLeft($str, 1)         $str = StringTrimRight($str, 1)         $ufelems = StringRegExp($str, "(\[.*?\]|.*?[^\\])(?:,|\z)", 3)         Dim $obj[1]         For $elem In $ufelems             $insObj = _FromJSONString($elem)             If $insObj = False And @error = 1 Then $insObj = 'Error in syntax of piece of JSONString: "' & $elem & '"'             _ArrayAdd($obj, $insObj)         Next         _ArrayDelete($obj, 0)     Else         SetError(1)         Return (False)     EndIf     Return ($obj) EndFunc   ;==>_fromJSONString

Much easier on the eyes :)

Edited by wraithdu, 09 October 2009 - 03:50 AM.


#11 BAM5

BAM5

    Wayfarer

  • Active Members
  • Pip
  • 90 posts

Posted 09 October 2009 - 04:11 AM

Something like this:

For $i = 0 To Ubound($arrayToTest) -1 Step 1 $test = $arrayToTest[$i] If IsArray($test) Then MsgBox(0,"Detected An Array", "The element at position: " & $i & " is an array") EndIf Next


IsArray can determine if something is an array, so you'd loop through the elements, recursively for multi-dimensional arrays.

I'm not sure how that detects multi-dimensional arrays :)

And sweet, thanks for the SRE again. I never really learned SRE at all since I had a pretty small attention span when I was looking at it :) But I know what it does and I get the gist of it, just never learned all the symbols, what they do, etc.

#12 Cynagen

Cynagen

    Seeker

  • Active Members
  • 37 posts

Posted 11 October 2009 - 03:43 AM

I'm not sure how that detects multi-dimensional arrays :)

And sweet, thanks for the SRE again. I never really learned SRE at all since I had a pretty small attention span when I was looking at it :) But I know what it does and I get the gist of it, just never learned all the symbols, what they do, etc.


Dood, thank you for posting this when you did, I am working on a project which requires interaction with a webserver which does handle some data in JSON, actually important stuff, so now I don't have to use a PHP intermediary to get what I'm looking for anymore!

Sadly, this UDF isn't working 100%, you're not handling subarrays at all, and single quote encapsulated strings, they're not being handled properly at all, also curly braces {}, aren't being handled, and throw up exceptions like crazy.

Edited by Cynagen, 11 October 2009 - 06:35 AM.

Blah, blah, blah... lip service... lip service.Working on a number of projects right now, just waiting for my time to post them here on AutoIt forums.

#13 Will66

Will66

    Polymath

  • Active Members
  • PipPipPipPip
  • 202 posts

Posted 14 October 2009 - 05:29 AM

Well today I was making a program and wanted to store a few parameters and variables and whatnot. It's been ages since I've worked with AutoIt (no reason why, just have been doing other type of developing) and thought to use JSON since I use it quite a bit to transfer and store information with javascript.

I'm not convinced but you got me thinking about adding at little ooP to $variables like $myCat.name="spotty".
Of course this is against syntax rules and $myCat is not an Object. But we can do this:

$obama = _newObject("Obama") _addProperty($obama,"Title","President")

So i made a little start to see if its useful or not? And bam5's topic heading looks like a good place to put it.



demo:
Plain Text         
#include <oop.au3> $obama = _newObject("Obama") ConsoleWrite($obama & @CRLF & @CRLF) _addProperty($obama,"Title","President") _addProperty($obama,"FirstName","Barack") _addProperty($obama,"HomeState","Chicago") $answer=_getProperty($obama,"Title") ConsoleWrite($answer & @CRLF) $answer=_getProperty($obama,"FirstName") ConsoleWrite($answer & @CRLF & @CRLF) for $p in _lengthObject($obama)     ConsoleWrite("Array: " & $p & @CRLF) Next _deleteProperty($obama,"HomeState") ConsoleWrite(@CRLF) for $p in _lengthObject($obama)     ConsoleWrite("After Delete: " & $p & @CRLF) Next _deleteObject($obama) ConsoleWrite(@CRLF) for $p in _lengthObject($obama)     ConsoleWrite("After Delete2: " & $p & @CRLF) Next

oop.au3:
Plain Text         
Global $js Func _deleteProperty($obj5="",$property="")     $js.AddCode("delete " & $obj5 & "." & $property & ";") EndFunc Func _lengthObject($obj4="")     $arrString = $js.eval("str='';c=0;for(i in " & $obj4 & "){if(c>0){str+='|';}else{c=1;} str+=i + ','+ " & $obj4 &"[i];}")     ;MsgBox(0,"",$arrString) ;debug     Return StringSplit($arrString,"|") EndFunc Func _getProperty($obj3="",$property="")     return $js.eval($obj3 & "." & $property & ";") EndFunc Func _addProperty($obj2="",$property="",$value="")     $invcomma=""     if IsString($value) then         $invcomma="'"     EndIf     $property=StringReplace($property," ","")     $js.AddCode("" & $obj2 & "." & $property & "="  & $invcomma & $value & $invcomma & ";") EndFunc Func _newObject($obj="")     If Not IsObj($js) Then         $js=ObjCreate("ScriptControl")         $js.language="Javascript"     EndIf     $js.AddCode("var " & $obj & " = new Object;")     return $obj EndFunc Func _deleteObject($obj="")     $js.AddCode("var " & $obj & "='';") EndFunc

Edited by Will66, 14 October 2009 - 05:30 AM.


#14 ValeryVal

ValeryVal

    Dig the way

  • Active Members
  • PipPipPipPipPipPip
  • 453 posts

Posted 15 October 2009 - 09:47 AM

I didn't know that there is the instance of OO Obama from Chicago...
:)
The point of world view

#15 BAM5

BAM5

    Wayfarer

  • Active Members
  • Pip
  • 90 posts

Posted 16 October 2009 - 03:06 AM

Dood, thank you for posting this when you did, I am working on a project which requires interaction with a webserver which does handle some data in JSON, actually important stuff, so now I don't have to use a PHP intermediary to get what I'm looking for anymore!

Sadly, this UDF isn't working 100%, you're not handling subarrays at all, and single quote encapsulated strings, they're not being handled properly at all, also curly braces {}, aren't being handled, and throw up exceptions like crazy.

Well first, sub-arrays are working fine, take a look at the test script and make sure you're assigning the sub-array to a different variable and not trying to access the sub-array in this method: $array[0][0]. That would be specifying a multi-dimensional array and not the sub-array. This is kind of silly, but that's how autoit works.

You are correct, single quotes are not working.

Braces specify an object and Autoit isn't a OOP language so it's only natural that there's no support for it.

Speaking of quote marks, if someone would be so kind as to add to the SRE the different types of string initializers I would really appreciate it!

#16 Gabriel13

Gabriel13

    Seeker

  • Active Members
  • 9 posts

Posted 17 October 2009 - 01:33 AM

Hello,

I've got a mature, two-year-old JSON UDF I'll be posting this weekend, once I'm able to start a new topic in the Example Scripts forum.

#17 Cynagen

Cynagen

    Seeker

  • Active Members
  • 37 posts

Posted 17 October 2009 - 06:20 AM

Well first, sub-arrays are working fine, take a look at the test script and make sure you're assigning the sub-array to a different variable and not trying to access the sub-array in this method: $array[0][0]. That would be specifying a multi-dimensional array and not the sub-array. This is kind of silly, but that's how autoit works.

You are correct, single quotes are not working.

Braces specify an object and Autoit isn't a OOP language so it's only natural that there's no support for it.

Speaking of quote marks, if someone would be so kind as to add to the SRE the different types of string initializers I would really appreciate it!

Here's a quick patch for single-quoted strings, and added a handler for : in a string (it causes an exception in the decoder.)

Also I looked into the array test, and have adjusted my PHP JSON output accordingly, and with great results, now dropping all the curly braces.

Here's the JSON UDF single-quote patch:
Func _FromJSONString($str)     If StringLeft($str, 1) = '"' And StringRight($str, 1) = '"' And Not (StringRight($str, 2) = '\"') Then         $obj = StringReplace(StringReplace(StringReplace(_StringRemoveFirstLastChar($str, '"'), '\"', '"'), '\,', ','),'\:',':')     elseif StringLeft($str, 1) = "'" And StringRight($str, 1) = "'" And Not (StringRight($str, 2) = "\'") Then         $obj = StringReplace(StringReplace(StringReplace(_StringRemoveFirstLastChar($str, "'"), "\'", "'"), '\,', ','),'\:',':')

Blah, blah, blah... lip service... lip service.Working on a number of projects right now, just waiting for my time to post them here on AutoIt forums.

#18 BAM5

BAM5

    Wayfarer

  • Active Members
  • Pip
  • 90 posts

Posted 20 October 2009 - 01:07 AM

Oh nice, I wasn't aware that the SRE actually looked for single quotes or is it that you're using the older version without the SRE?

Edited by bam5, 20 October 2009 - 01:11 AM.


#19 jcampbell

jcampbell

    Seeker

  • Active Members
  • 26 posts

Posted 26 August 2013 - 09:17 PM

I am hoping someone is still watching this thread.  I have tried to use the FromJSONString function to convert a JSON response into an array.  I may have missed what this is doing all together since I am new to dealing with JSON and array functions inside of AutoIT. 

 

When I try the function I am unable to tell if it breaks it into a usable array or if it is through an error.  The only thing listed in the console window is an Exit code of 0.  I tried adding in a _arraydisplay call but it then gives me an error about my variable being used before it is declared. Hopeing for some help or atleast a gentle nudge in the correct direction as I am still learning.

 

Eventually what this code will be used for is to display the items under the header section Name in a dropdown dialog box for the user to select for another operation.

 

Thanks

AutoIt         
;Includes #Include <WinAPI.au3> #include <Array.au3> $restReq = ObjCreate("winhttp.winhttprequest.5.1") $restGuid = _CreateGuid() ;Dialogs for testing remark out for production use MsgBox (4096,"My Computer Name",@ComputerName) MsgBox (4096,"My Name",@UserName) MsgBox(4096, "Generate Guid", $restGuid) ;REST Request Section $restReq.Open("GET", "http://kcm-rev-t01/RevitServerAdminRESTService2013/AdminRESTService.svc/ /Contents", False) $restReq.setRequestHeader ("User-Name", @UserName) $restReq.setRequestHeader ("User-Machine-Name", @ComputerName) $restReq.setRequestHeader ("Operation-GUID", $restGuid) $restReq.Send() $oReceived = $restReq.ResponseText $oStatusCode = $restReq.Status ;Dialog box of status code for troubleshooting MsgBox(4096, "Status Code", $oStatusCode()) If $oStatusCode == 200 then  $file = FileOpen("Received.txt", 2) ; The value of 2 overwrites the file if it already exists  FileWrite($file, $oReceived)  FileClose($file)  MsgBox(4096, "My test for Nolan", $oReceived ())  $str = $restReq.ResponseText ;Turn my JSON string into an array  _FromJSONString($str) EndIf ;-------Section for called functions------------------------------------------------------ Func _CreateGuid()     Local $Guid = DllStructCreate($tagGUID)     $Result = DllCall("OLE32.DLL", "dword", "CoCreateGuid", "ptr", DllStructGetPtr($Guid))     $Result = _WinAPI_StringFromGUID(DllStructGetPtr($Guid))  $strresult = StringTrimLeft($Result, 1)  $strresult = StringTrimRight($strresult, 1)  Return $strresult EndFunc Func _FromJSONString($str)     If StringLeft($str, 1) = '"' And StringRight($str, 1) = '"' And Not (StringRight($str, 2) = '\"') Then         $obj = StringReplace(StringReplace(_StringRemoveFirstLastChar($str, '"'), '\"', '"'), '\,', ',')     ElseIf $str = "true" Then         $obj = True     ElseIf $str = "false" Then         $obj = False     ElseIf StringLeft($str, 2) = "0x" Then         $obj = Binary($str)     ElseIf StringIsInt($str) Then         $obj = Int($str)     ElseIf StringIsFloat($str) Then         $obj = Number($str)     ElseIf StringLeft($str, 1) = '[' And StringRight($str, 1) = ']' Then         $str = StringTrimLeft($str, 1)         $str = StringTrimRight($str, 1)         $ufelems = StringRegExp($str, "(\[.*?\]|.*?[^\\])(?:,|\z)", 3)         Dim $obj[1]         For $elem In $ufelems             $insObj = _FromJSONString($elem)             If $insObj = False And @error = 1 Then $insObj = 'Error in syntax of piece of JSONString: "' & $elem & '"'             _ArrayAdd($obj, $insObj)         Next         _ArrayDelete($obj, 0)     Else         SetError(1)         Return (False)     EndIf     Return ($obj) _ArrayDisplay($obj,"This is my array") EndFunc   ;==>_fromJSONString ; =================================================================== ; _StringRemoveFirstLastChar($str, $char[, $firstCount=1[, $lastCount=1]]) ; ; Removes characters matching $char from the beginning and end of a string ; ; Parameters: ;   $str - IN - String to search search modify and return ;   $char - IN - Character to find and delete in $str ;   $firstCount - OPTIONAL IN - How many to delete from the beginning ;   $lastCount - OPTIONAL IN - How many to delete from the end ; Returns: ;   Modified string ; Remarks: ;   Could probably be easily turned into a replace function ;                   (But I'm too lazy :P ) ; =================================================================== Func _StringRemoveFirstLastChar($str, $char, $firstCount = 1, $lastCount = 1)     $returnString = ""     $splited = StringSplit($str, '"', 2)     $count = 1     $lastCount = UBound($splited) - $lastCount     For $split In $splited         $returnString &= $split         If $count > $firstCount And $count < $lastCount Then $returnString &= '"'         $count += 1     Next     Return ($returnString) EndFunc   ;==>_StringRemoveFirstLastChar

JSON response

{"Path":" ","DriveFreeSpace":5527474176,"DriveSpace":21338517504,"Folders":[{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"BrownBag Data Sets - Copy","Size":109291371},{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"BrownBag Data Sets","Size":149631426},{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"Client","Size":0},{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"Common","Size":32254916},{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"Design_Applications","Size":494052071},{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"Jeff2","Size":125896374},{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"Jeff3","Size":226184397},{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"RS_Test001","Size":267912955},{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"ssd testing","Size":1028023115},{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"JeffJr","Size":1204698584},{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"Jeff5","Size":306247343}],"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Models":[{"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"ModelSize":49180384,"Name":"Macro_Base","ProductVersion":3,"SupportSize":6097}]}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users