JSON help

Started by KAKAN, Dec 06, 2015, 10:40 AM

Previous topic - Next topic

KAKAN

Hmm, I was trying the functions of the JSON plugin, toJSON and toJSONFile both works perfectly.
I was trying the fromJSON, it doesn't work properly.
Here's what I tried:-
exec local file = file("data.json","r"); print( fromJSON(file) );Here's what data.json contains:-
{
   "name": "[0.4]BABAKAKAN's Server",
   "ip2": "babakakan.noip.me"
 }
I created that JSON code using toJSONFile.
Here's the error which got produced when I ran the 1st code( fromJSON ):-
Error in 'fromJSON': Wrong number of arguments or invalid argument type
I tried this too:-
print( fromJSONFile("data.json") );The following error/output I got:-
(table:0x000....)Can someone tell me my mistake?
oh no

Xmair

This is VC:MP's squirrel scripting board, you can only ask for squirrel help.
go away hush

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

KAKAN

Quote from: Xmair on Dec 06, 2015, 12:04 PMThis is VC:MP's squirrel scripting board, you can only ask for squirrel help.
go away hush
That plugin is also for VCMP and it is used with VCMP Squirrel scripts.
and if not, where shall I ask?
oh no

DizzasTeR

Run a foreach loop and print all the stuff in that table which is getting returned.

Thijn

How is that an error? It's printing what it is, a table.
Try printing an element.
local test = fromJSONFile("data.json");
if ( test ) {
print( test.name );
}

DizzasTeR

More precisely I was surprised you don't even know how to work with tables that you are asking that...

KAKAN

Quote from: Thijn on Dec 06, 2015, 09:58 PMHow is that an error? It's printing what it is, a table.
Try printing an element.
local test = fromJSONFile("data.json");
if ( test ) {
print( test.name );
}
Thanks!
Locked, marked as solved.
oh no