Sign in to follow this  
Followers 0

JSON UDF

19 posts in this topic

#1 ·  Posted (edited)

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:

; ===================================================================
; 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.

JSON.au3

Edited by bam5

[center]JSON Encoding UDF[/center]

Share this post


Link to post
Share on other sites



#2 ·  Posted

"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!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try this SRE in your _FromJSONString() function:

$ufelems = StringRegExp($str, "(\[.*?\]|.*?[^\\])(?:,|\z)", 3)

This could replace that complex string array parsing.

Edited by wraithdu

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

EDIT: And also, your _StringRemoveFirstLastChar() could be much simpler if you use StringTrimLeft() and StringTrimRight()

Edited by Minikori

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.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Share this post


Link to post
Share on other sites

#6 ·  Posted

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)

Share this post


Link to post
Share on other sites

#7 ·  Posted

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.)

Share this post


Link to post
Share on other sites

#8 ·  Posted

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! :)


[center]JSON Encoding UDF[/center]

Share this post


Link to post
Share on other sites

#9 ·  Posted

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.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

This will do it:

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

Share this post


Link to post
Share on other sites

#11 ·  Posted

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.


[center]JSON Encoding UDF[/center]

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

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

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.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

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:

#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:

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

Share this post


Link to post
Share on other sites

#14 ·  Posted

I didn't know that there is the instance of OO Obama from Chicago...

:)


The point of world view

Share this post


Link to post
Share on other sites

#15 ·  Posted

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!


[center]JSON Encoding UDF[/center]

Share this post


Link to post
Share on other sites

#16 ·  Posted

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.


[url='http://www.autoitscript.com/forum/index.php?showtopic=104150']JSON UDF Library (fully RFC4627-compliant)[/url][url='http://www.autoitscript.com/forum/index.php?showtopic=104325']Keep Windows Clear of Top Taskbar (for those who like their taskbar on top)[/url]

Share this post


Link to post
Share on other sites

#17 ·  Posted

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.

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

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

[center]JSON Encoding UDF[/center]

Share this post


Link to post
Share on other sites

#19 ·  Posted

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

;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}]}

Share this post


Link to post
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
Sign in to follow this  
Followers 0