Jump to content

how to get info form json file


Recommended Posts

#include <File.au3>
#include <JSON.au3>

$sFilePath = @ScriptDir & "Latin.json"
$hFileOpen = FileOpen($sFilePath, $FO_READ)
 
there is a line inside the Latin.json file that looks like this 
{"pos": "verb", "head_templates": [{"name": "la-verb-form", "args": {"1": "abestis"}, "expansion": "abestis"}], "word": "abestis", "lang": "Latin", "lang_code": "la", "senses": [{"raw_glosses": ["second-person plural present active indicative of absum"], "glosses": ["second-person plural present active indicative of absum"], "tags": ["active", "form-of", "indicative", "plural", "present", "second-person"], "form_of": [{"word": "absum"}], "id": "abestis-la-verb-so45elH9", "categories": []}]}

and i want to get this line through the word "abestis" using this code , and it didnt work out
 

ConsoleWrite("name  = " & json_Get($oJSON, '["word"]') & @CRLF)

 

Link to comment
Share on other sites

On 11/2/2022 at 1:21 AM, jacky998877 said:
#include <JSON.au3>

 

and i want to get this line through the word "abestis" using this code , and it didnt work out

That library is not included in standard Autoit, so we don't know which one you use.

 

With using Wards library

 

 

#include <Json.au3>

$data = '{"pos": "verb", "head_templates": [{"name": "la-verb-form", "args": {"1": "abestis"}, "expansion": "abestis"}], "word": "abestis", "lang": "Latin", "lang_code": "la", "senses": [{"raw_glosses": ["second-person plural present active indicative of absum"], "glosses": ["second-person plural present active indicative of absum"], "tags": ["active", "form-of", "indicative", "plural", "present", "second-person"], "form_of": [{"word": "absum"}], "id": "abestis-la-verb-so45elH9", "categories": []}]}'
$Obj = Json_Decode($data)
ConsoleWrite("data is equal = " & Json_Get($Obj, '[word]') & @CRLF)
;data is equal = abestis
Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

For such a simple request maybe you could use a simpler way

$line = '{"pos": "verb", "head_templates": [{"name": "la-verb-form", "args": {"1": "abestis"}, "expansion": "abestis"}], "word": "abestis", "lang": "Latin", "lang_code": "la", "senses": [{"raw_glosses": ["second-person plural present active indicative of absum"], "glosses": ["second-person plural present active indicative of absum"], "tags": ["active", "form-of", "indicative", "plural", "present", "second-person"], "form_of": [{"word": "absum"}], "id": "abestis-la-verb-so45elH9", "categories": []}]}'

Msgbox(0,"", "name = " & StringRegExpReplace($line, '.*?"word":\s"([^"]+).*', "$1") )

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...