Sydious wrote:as i said, I am still confused how to use jsons but this is how the majority of my jsons are created. I am more going through the motions, then actually fully understanding it. I know there are objects and arrays , but just don't get the diffrence between the two, which to use when, and how to create each type.
Ok... real simple:
- json objects are key/value pairs. There is no ordering. The where does not matter, when you ask an object for it's "AC"(or whatever) it just gives you back the value if there is one. Thing of this like a "person" object who has keys of
- "eye color" = "brown"
- "hair color" = "black"
- "height" = "5 foot 6 inches"
- json objects are an ordered list of things. Typically, you would use this if you need to maintain order of something, say for example a person's work history in chronological order.
Now.. the real trick is knowing when to use which and it really depends on context. Going back to the person example, you might have something like:
Code: Select all
{
"Person": {
"Name": "Rob",
"Hair": "Black",
"Children": [
"Jill",
"Henry",
"Bill"
]
}
}
so you have a person object with child objects of Name, Hair, and Children. Name and Hair's values are simple strings, while Children's value is an array. The Children array has an explicit order, but what context is there to say what the ordering means? If you NEED that context or any other information about the children (such as THEIR hair color, eye color, etc, then Children's value would be much better as an object itself for each child or an array. If you want to keep the ordering(say oldest age going down), you would do something like:
Code: Select all
{
"Person": {
"Name": "Rob",
"Hair": "Black",
"Children": [
{
"Name": "Jill",
"Hair": "blue",
"Age": 18
},
{
"Name": "Henry",
"Hair": "Brown",
"Age": 14
},
{
"Name": "Bill",
"Hair": "Black",
"Age": 8
}
]
}
}
Now, with this example, you can track the children's ages in order. If for some really odd reason Rob found out he had another child that was 16(bad Rob!!!), you would have to loop over the Children array, check each's Age property and store the previous child's age value and insert the Children into a NEW array with the new child in the correct place.
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.
Get your Dropbox 2GB via my
referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..