[plugin] JSON (import/export/generate/edit/inspect/...)

Post your work in progress addons and get feedback

Post » Fri Jan 09, 2015 11:33 pm

@yann

Gotcha. No worries, thanks for the update.
B
62
S
19
G
8
Posts: 341
Reputation: 12,075

Post » Wed Feb 04, 2015 1:23 pm

Hi, great plugin!!
just some question (sorry):

is it possible to count the objects?
e.g. I have one json file with several objects (like wizard, hunter,...) and I want that the program counts them and put it in a global variable.
In this case: there are wizard, hunter, Knight, farmer -> global variable: 4

if not: I named the objects 1,2,3 and 4. Can it put the highest object in the variable. I tried it with instance.variable, but it always says "0"
------------------------------------------

other question: is it possible to choose/open a json file with function?
e.g. function(car)
in the function: set text to car.value(0,0,1)

I tried with variable, but the program didn't accepted it
e.g. function(car)
set function.param(0) to Database
set text to database.value(0,0,1) <- error

I would like to use one function instead making it for several databases.


[solved] I had to use: " pick by comparison "
Last edited by edwardr on Mon Feb 09, 2015 10:28 am, edited 1 time in total.
B
15
S
4
Posts: 77
Reputation: 1,030

Post » Mon Feb 09, 2015 10:04 am

@Yann

Very usefull plugin, but I think there's a bug in "Get Size" method:

for each property at current > JSON.Size(JSON.CurrentKey) always returns 2, no matter how I try

OK, found it out. It should be similar to the array's "Length" method, with an argument (1):

for each property at current >JSON.Size(1)
B
45
S
11
G
4
Posts: 515
Reputation: 7,389

Post » Mon Feb 09, 2015 11:25 am

@edwardr

you can count objects by the method I described above^
B
45
S
11
G
4
Posts: 515
Reputation: 7,389

Post » Fri Mar 13, 2015 5:59 pm

@Yann Very nice work my friend! Working well so far. One trick escapes me: I have an array of objects I need to get into.

How would I get to the attribs in an object within an array? Like...

Code: Select all
{
    "_id": "blahblahid",
    "units": [
        { "unitId": "blahUnitID1", "qty": 7 },
        { "unitId": "blahUnitID2", "qty": 5 },
        { "unitId": "blahUnitID3", "qty": 3 },
    ]
}


How would I get to the units[1].unitId or units[2].qty?
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Sun Mar 15, 2015 4:47 pm

@locohost
from memory I'd say:
Code: Select all
JSON.Value(0, "units", 1, "unitID")
JSON.Value(0, "units", 2, "qty")


the arguments are to be read as:
1st: 0 = root, 1 = current (current is used un foreach loops and I think you also have an action to set it)
2nd: "units" is one of the key of your root object's member (if the root were an array , you would use the index)
3rd: the index of the "units" array
4th: "unitId" or "qty" one of the key of one of the object in the "units" array
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Mon Mar 16, 2015 10:00 am

Seems to be working. Thank you very much!!
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Sun Apr 26, 2015 9:31 pm

@Yann

I seem to be having a issue with C2 working with JSON data. I am simply trying to load a JSON raw into your plugin
Code: Select all
{
"Bob":{
     "Skill1":"AA",
     "Skill2":"BA",
     "Skill3":"CA"},
"Ted":{
     "Skill1":"AB",
     "Skill2":"BB",
     "Skill3":"CB"},
"Mike":{
     "Skill1":"AC",
     "Skill2":"BC",
     "Skill3":"CC"}
 }


What is wrong with this syntax? The first "{" has a red line under it so there has to be something wrong with how I am wighting this JSON. Your plugin seems to be just exactly what I need but I have no clue as to why my code is getting this error.

I'm sure its something that I am doing stupid

I can get it to work by changing it to

Code: Select all
"{
""Bob"":{
     ""Skill1"":""AA"",
     ""Skill2"":""BA"",
     ""Skill3"":""CA""},
""Ted"":{
     ""Skill1"":""AB"",
     ""Skill2"":""BB"",
     ""Skill3"":""CB""},
""Mike"":{
     ""Skill1"":""AC"",
     ""Skill2":""BC"",
     ""Skill3"":""CC""}
 }"


But then its not a JSON and having too many " means just that much more likely that I will miss one and screw the whole thing.
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
B
7
S
2
Posts: 113
Reputation: 1,245

Post » Mon Apr 27, 2015 1:45 pm

@CrazyVulcan
That's because C2 expects a string, a string in C2 is some characters (or none) surrounded by double quotes (")
Problem is, what happens if you want you string to contains double quotes?
Answer: you need to escape them.
How to escape them?
some languages use \" C2 use double double quote ""

As a small remark, C2 isn't THAT weird in this area, you also do that if you want to escape double quotes in verbatim string literals in C#
http://stackoverflow.com/questions/1928909/can-i-escape-a-double-quote-in-a-verbatim-string-literal

Now, one way to avoid this messy escaping is to put your pretty json inside a file you import in the project, and you get retreive it using Ajax.
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Tue Apr 28, 2015 4:25 am

Yann wrote:@CrazyVulcan
That's because C2 expects a string, a string in C2 is some characters (or none) surrounded by double quotes (")
Problem is, what happens if you want you string to contains double quotes?
Answer: you need to escape them.
How to escape them?
some languages use \" C2 use double double quote ""

As a small remark, C2 isn't THAT weird in this area, you also do that if you want to escape double quotes in verbatim string literals in C#
http://stackoverflow.com/questions/1928909/can-i-escape-a-double-quote-in-a-verbatim-string-literal

Now, one way to avoid this messy escaping is to put your pretty json inside a file you import in the project, and you get retreive it using Ajax.


Thanks @Yann, sure enough using AJAX did the trick. Quick question how big a JSON file can your plugin handle out of curiosity? Im sure I will find out but in my game each player has the ability to unlock various things as well as saving user created items that they can use later. I would love to just put all of it in one JSON using various tables if posable. Dose that seem doable?
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
B
7
S
2
Posts: 113
Reputation: 1,245

PreviousNext

Return to Work in Progress Addons

Who is online

Users browsing this forum: No registered users and 0 guests