Jump to content

A Non-Strict JSON UDF (JSMN)


Ward
 Share

Recommended Posts

  • Developers

Any source posted can be freely used unless specified otherwise. :) 
Some recognition about  its use is ofcourse a common courtesy.

Jos 

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

27 minutes ago, loulou2522 said:

Where can i  fin and downlaod  json.au3. ?

The bottom of the first post of this topic.

 

Edited by TheXman
Link to comment
Share on other sites

  • 1 month later...
  • Developers

Correct as there's an issue with that latest version that I have been unable to resolve I reverted to the previous version. 
Updates the first post and change the last text with a strikethrough so it is clear, but the line above does contain the file and the reason for reverting.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...

Hello. I have json like this 

{"response":("userid":"4798","success":1)}

Please, help me add this values to variables, I have "Error: Error in expression" :(

 

$object = json_decode($data)
$message=json_get($object,["userid"])
MsgBox("","Test",$message)

I want make like this logic: if success = 1 then popup message with "4798" (userid content), else (if success = 0) then message with "error".

Link to comment
Share on other sites

23 minutes ago, auitden said:

{"response":("userid":"4798","success":1)}

Your JSON example is invalid.  Just plug it into any JSON validator on the web and you will see.  It most likely should have been something like:

{"response":{"userid":"4798","success":1}}

 

Correct your JSON and try again.

 

Use the json_dump() function to get an idea of how to reference json values using the dot-notation.

#include <MyIncludes\json\json.au3>  ;<== Change to your location

$data = '{"response":{"userid":"4798","success":1}}'

Json_Dump($data)

$object = json_decode($data)
$message=json_get($object,".response.userid")  ;using dot-notation
;~ $message=json_get($object,"[response][userid]")  ;using bracket-notation
MsgBox("","Test",$message)

Output:

+-> .response.userid  =4798
+-> .response.success  =1

 

@auitden: I updated my response with an example using your original script snippet.

Edited by TheXman
Link to comment
Share on other sites

#include "Json.au3"

TestThis()
Func TestThis()
    
    Local $myJson = '{"response":{"userid":"4798","success":1}}'
    Json_Dump($myJson) ; to get what you look for
    
    Local $oTemp = Json_Decode($myJson)
    Local $my_userid = Json_ObjGet($oTemp, ".response.userid") ; use what you look for here
    Local $my_success = Json_ObjGet($oTemp, ".response.success")
    
    ConsoleWrite('- $my_userid = "' & $my_userid & '"' & @CRLF)
    ConsoleWrite('- $my_success = ' & $my_success & @CRLF)
    
EndFunc

:) 

Edited by argumentum
better code

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

_INetGetSource ( $sURL [, $bString = True] )
$sURL(The URL of the site.) eg 'http://www.autoitscript.com'
$bString[optional] If True the data is returned in string format, otherwise binary format.

$data = _INetGetSource($URL) <-- without the URL that is all the help I can give but try to ConsoleWrite('"' & $data & '"' & @CRLF) ;) 

Edit: I'd use binary and do my own bin2str conversion

Edited by argumentum
better

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

6 minutes ago, argumentum said:

_INetGetSource ( $sURL [, $bString = True] )
$sURL(The URL of the site.) eg 'http://www.autoitscript.com'
$bString[optional] If True the data is returned in string format, otherwise binary format.

$URL="http://192.168.1.50"
$data = _INetGetSource($URL , $bString = 'True')

;$data = '{"response":{"userid":"4798","success":1}}'

Json_Dump($data)
$object = json_decode($data)
$message=json_get($object,".response.userid")
MsgBox("","Test",$message)

Blank screen :(

Link to comment
Share on other sites

4 minutes ago, argumentum said:

1) 192.168.1.50 is your internal IP
2) $bString = 'True' will equal false( i guess ), so use True or False.

1) it's for example, i can't share this :(

2) true or false, i already have this in console output:

"0x7B22726573706F6E7365223A7B22737465616D6964223A363536313139383939363737313336...654433"

 

Link to comment
Share on other sites

9 minutes ago, auitden said:

"0x7B22726573706F6E7365223A7B

ok, this is compressed HTML ?, ...these first characters are not "text", they are control characters. Also, this is not JSON related anymore, so, I would open a help thread in the help section to keep the unrelated help concise. 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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

×
×
  • Create New...