B4l4 Posted October 25, 2019 Share Posted October 25, 2019 Hi, I've read all the postings about parsing JSONs but I can't for the life of me get it to work. I'm trying to extract the "name" and the "value". This is what I've done. #include "Json.au3" $response='{"raw":{},"class":[{"name":"infer","value":"88.1"}],"ref":"ver1","ex":null,"pr":null,"n":null,"re":null,"res":null}' $oJSON = Json_Decode($response) Local $str = json_Get($oJSON, '["class"]["name"]') ConsoleWrite($str) Please help! Thanks. Link to comment Share on other sites More sharing options...
TheXman Posted October 25, 2019 Share Posted October 25, 2019 (edited) You were close. The json_dump() function is always helpful in trying to figure out the correct notation for accessing values. As it is named, it dumps all of the values with their corresponding, dot notation, accessors. Below, I slightly modified your code to show you how to use the json_dump() function and how to access your values using both bracket and dot notation. I hope that helps. #include "Json.au3" $response = '{"raw":{},"class":[{"name":"infer","value":"88.1"}],"ref":"ver1","ex":null,"pr":null,"n":null,"re":null,"res":null}' $oJSON = Json_Decode($response) ; Dump the json values Json_Dump($response) ; Bracket notation ConsoleWrite("name = " & json_Get($oJSON, '["class"][0]["name"]') & @CRLF) ConsoleWrite("value = " & json_Get($oJSON, '["class"][0]["value"]') & @CRLF) ; Dot notation ConsoleWrite("name = " & json_Get($oJSON, '.class[0].name') & @CRLF) ConsoleWrite("value = " & json_Get($oJSON, '.class[0].value') & @CRLF) Output: +-> .class[0].name =infer +-> .class[0].value =88.1 +-> .ref =ver1 +-> .ex =Null +-> .pr =Null +-> .n =Null +-> .re =Null +-> .res =Null name = infer value = 88.1 name = infer value = 88.1 Edited October 25, 2019 by TheXman B4l4, Danp2 and FrancescoDiMuro 2 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now