Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: KAKAN on Dec 06, 2015, 10:40 AM

Title: JSON help
Post by: KAKAN on Dec 06, 2015, 10:40 AM
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?
Title: Re: JSON help
Post by: Xmair on Dec 06, 2015, 12:04 PM
This is VC:MP's squirrel scripting board, you can only ask for squirrel help.
go away hush
Title: Re: JSON help
Post by: KAKAN on Dec 06, 2015, 12:19 PM
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?
Title: Re: JSON help
Post by: DizzasTeR on Dec 06, 2015, 01:00 PM
Run a foreach loop and print all the stuff in that table which is getting returned.
Title: Re: JSON help
Post by: Thijn on Dec 06, 2015, 09:58 PM
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 );
}
Title: Re: JSON help
Post by: DizzasTeR on Dec 07, 2015, 02:24 AM
More precisely I was surprised you don't even know how to work with tables that you are asking that...
Title: Re: JSON help
Post by: KAKAN on Dec 07, 2015, 08:34 AM
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.