JSON with FiveM

Tutoriale, ghiduri de optimizare si suport pentru crearea serverelor.
Post Reply
User avatar
greenie
Full Member
Full Member
Posts: 2704
Joined: Sun Nov 21, 2021 4:55 pm
Jucator SA:MP ?: Nu
Nick:: greenie
Jucator CS ?: Da

JSON with FiveM

Post by greenie »

Inserting an array into a JSON file

local loadFile= LoadResourceFile(GetCurrentResourceName(), "./fileNameHere.json")
local information = {name = "w00pi the legend", age = 17, coolness = 1000}

SaveResourceFile(GetCurrentResourceName(), "fileNameHere.json", json.encode(information), -1)
^^
That will insert the array into the json file leaving the information array in the JSON file looking like this.

{"name" : "w00pi the legend", "age" : 17, "coolness" : 1000}
How to extract JSON information

local loadFile= LoadResourceFile(GetCurrentResourceName(), "./fileNameHere.json") -- you only have to do this once in your code, i just put it in since it wont get confusing.
local extract = {}
extract = json.decode(loadFile)
SaveResourceFile(GetCurrentResourceName(), "fileNameHere.json", json.encode(extract), -1)
π‘΄π’‚π’šπ’ƒπ’† 𝒕𝒉𝒆 𝑬𝒂𝒓𝒕𝒉 π’Šπ’” 𝒕𝒉𝒆 𝑯𝒆𝒍𝒍 𝒐𝒇 𝑨𝒏𝒐𝒕𝒉𝒆𝒓 𝑷𝒍𝒂𝒏𝒆𝒕... ☒️

βœ… GAZDUIRE JOCURI / VPS / GAZDUIRE WEB / SERVERE DEDICATE - Stock NELIMITAT / Valabil comandati pe https://www.zonek.ro/
Post Reply

Return to β€œServer Development”