Jump to content

Json Parsing Question


 Share

Recommended Posts

Hi All,  

Can anyone help me figure out the syntax to use to get the jobid returned out of the below json string (in my code example)?  I want to use bracketed notation and I want the msgbox to display 2155813bb95e9829.

One example I've tried that doesn't work is...

$strJobIDFromJson = json_Get($objJson, "[jobid]")

 

 

I'm using the json.au3 include with these properties...

; File        : Json.au3 (2015.01.08)
; Purpose    : A Non-Strict JavaScript Object Notation (JSON) Parser UDF
; Author    : Ward
; Dependency: BinaryCall.au3
; Website    : http://www.json.org/index.html
;
; Source    : jsmn.c
; Author    : zserge
; Website    : http://zserge.com/jsmn.html
;
; Source    : json_string_encode.c, json_string_decode.c
; Author    : Ward

 

Here's my example code...

#Include <JSON.au3>
$strReturnedData2 = '{"jobid":{"2155813bb95e9829":{"startTime":"2016-10-28 20:56:53 UTC","requestor":"Requestor","description":"Description","email":"","content":[{"Name":"ContentName","Parameters":""}],"computers":{"Computername":{"overallStatus":"Waiting for client to check-in...","details":[{"name":"DetailsName","env":"","actionID":"","status":"","exitCode":"","lastLine":"","startTime":"","endTime":"","contentURL":""}]}},"actionStatus":{"iem-dev":"Open"}}},"status_text":"","error_text":"","status_code":"200","status":"OK","rc":"0"}'
$objJson = json_Decode($strReturnedData2)
$strJobIDFromJson = json_Get($objJson, What Do I Put Here?)
MsgBox(0,"JobID",$strJobIDFromJson)

 

Thanks

 

 

Link to comment
Share on other sites

Hello. You can do this.

#include <JSON.au3>
Local $strReturnedData2 = '{"jobid":{"2155813bb95e9829":{"startTime":"2016-10-28 20:56:53 UTC","requestor":"Requestor","description":"Description","email":"","content":[{"Name":"ContentName","Parameters":""}],"computers":{"Computername":{"overallStatus":"Waiting for client to check-in...","details":[{"name":"DetailsName","env":"","actionID":"","status":"","exitCode":"","lastLine":"","startTime":"","endTime":"","contentURL":""}]}},"actionStatus":{"iem-dev":"Open"}}},"status_text":"","error_text":"","status_code":"200","status":"OK","rc":"0"}'
Local $objJson = json_Decode($strReturnedData2)
Local $strJobIDFromJson = json_Get($objJson, '["jobid"]').Keys[0]
ConsoleWrite($strJobIDFromJson & @CRLF)

 

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

Alternatively you could use a regular expression

$strReturnedData2 = '{"jobid":{"2155813bb95e9829":{"startTime":"2016-10-28 20:56:53 UTC","requestor":"Requestor","description":"Description","email":"","content":[{"Name":"ContentName","Parameters":""}],"computers":{"Computername":{"overallStatus":"Waiting for client to check-in...","details":[{"name":"DetailsName","env":"","actionID":"","status":"","exitCode":"","lastLine":"","startTime":"","endTime":"","contentURL":""}]}},"actionStatus":{"iem-dev":"Open"}}},"status_text":"","error_text":"","status_code":"200","status":"OK","rc":"0"}'

$jobid = StringRegExpReplace($strReturnedData2, '.*"jobid":\{"([^"]+).*', "$1")
MsgBox(0, "JobID", $jobid)

 

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