Page 1 of 1
Need help with array of objects !
Posted: Thu Jul 13, 2023 3:12 pm
by ruslanx
I have file job.json:
Code: Select all
[
{
"published": "",
"category": "",
"url": "",
"skills": ""
},
{
"published": "",
"category": "",
"url": "",
"skills": ""
},
{
"published": "",
"category": "",
"url": "",
"skills": ""
}
]
how to read values (url ...) ?
Re: Need help with array of objects !
Posted: Thu Jul 13, 2023 3:14 pm
by jacdelad
Take a look at the JSON library, especially ParseJSON().
Re: Need help with array of objects !
Posted: Thu Jul 13, 2023 3:20 pm
by ruslanx
after node js javascript I can't understand how to .. please give me example
Re: Need help with array of objects !
Posted: Thu Jul 13, 2023 3:21 pm
by Kiffi
ruslanx wrote: Thu Jul 13, 2023 3:20 pm
after node js javascript I can't understand how to .. please give me example
viewtopic.php?t=80283
Re: Need help with array of objects !
Posted: Thu Jul 13, 2023 3:32 pm
by ruslanx
Code: Select all
#JSON = 1
Global WorkPath$ = GetPathPart(ProgramFilename())
Global JobsFile$ = WorkPath$ + "jobs.json"
Structure JobData
published.s
category.s
url.s
skills.s
EndStructure
Global NewList J.JobData()
LoadJSON(#JSON, JobsFile$)
ExtractJSONStructure(JSONValue(#JSON), @J, JobData)
; what next ?
Re: Need help with array of objects !
Posted: Thu Jul 13, 2023 3:35 pm
by ruslanx
there is an object here is array of objects
Re: Need help with array of objects !
Posted: Thu Jul 13, 2023 3:43 pm
by StarBootics
Hello,
The modified json file :
Code: Select all
[
{
"published": "patato",
"category": "food",
"url": "www.patatoes.com",
"skills": "minimum"
},
{
"published": "patato",
"category": "food",
"url": "www.patatoes.com",
"skills": "minimum"
},
{
"published": "patato",
"category": "food",
"url": "www.patatoes.com",
"skills": "minimum"
}
]
Code: Select all
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Json Example
; File Name : Json Example.pb
; File version: 1.0.0
; Programming : OK
; Programmed by : StarBootics
; Date : July 13th, 2023
; Last Update : July 13th, 2023
; PureBasic code : V6.03 beta 2 LTS
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Structure Records
published.s
category.s
url.s
skills.s
EndStructure
Dim jobs.Records(3)
If LoadJSON(0, "job.json")
ExtractJSONArray(JSONValue(0), jobs())
EndIf
For Index = 0 To 2
Debug jobs(Index)\published
Debug jobs(Index)\category
Debug jobs(Index)\url
Debug jobs(Index)\skills
Debug ""
Next
; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
Best regards
StarBootics
Re: Need help with array of objects !
Posted: Thu Jul 13, 2023 3:55 pm
by ruslanx
Code: Select all
#JSON = 1
Global WorkPath$ = GetPathPart(ProgramFilename())
Global JobsFile$ = WorkPath$ + "jobs.json"
Structure JobData
published.s
category.s
url.s
skills.s
EndStructure
NewList Jobs.JobData()
If LoadJSON(#JSON,JobsFile$)
ExtractJSONList(JSONValue(#JSON), Jobs())
ForEach Jobs()
Debug Jobs()\published
Debug Jobs()\category
Debug Jobs()\url
Debug Jobs()\skills
Next
EndIf
thank you!