bignic

I'm new to JSON so I'm not clear as to why the Skeleton JSON object seems to have the bones in an array (as one would expect) but the Animation JSON objects appear NOT to?

Am I missing something?

That is, how does the deserialization work if there is no consistent object to deserialize to? (ie: "Left-Leg bone object", rather than just an array of generic "bone objects" with individual names...)

Does that makes sense?
bignic
  • 전체글: 14

Nate

It isn't clear what you mean by what you wrote. Arrays are used in JSON when order matters otherwise maps are used.
사용자 아바타
Nate

Nate
  • 전체글: 11857

bignic

I'm sure this is more of a JSON question than spine but, for example:

In the Animation JSON, the Bones object has sub objects of "leg right" and "leg right lower", while in the Skeleton JSON, the Bones object has an array of sub objects.

I just don't understand why the Animation JSON wouldn't list the bones as an array also?

Skeleton
{
"bones": [
{ "name": "root" },
{ "name": "hips", "parent": "root", "length": 47.04, "x": -19.6, "y": 101.55, "rotation": 0.9 },
{ "name": "leg right", "parent": "hips", "length": 44.51, "x": 36.46, "y": -4.77, "rotation": -90.45 },
{ "name": "leg right lower", "parent": "leg right", "length": 40.04, "x": 44.13, "y": 3.39, "rotation":
]
}
Skeleton Animation
{
"bones": {
"leg right": {
"rotate": [
{ "time": 0, "angle": 26.88 },
{ "time": 0.5, "angle": 13.79 },
{ "time": 0.6666, "angle": 26.88 }
],
},
"leg right lower": {
"rotate": [
{ "time": 0, "angle": -2.34 },
{ "time": 0.6666, "angle": -2.34 }
],
}
}
bignic
  • 전체글: 14

Nate

Ah. It's a style choice. Below would be the equivalent if using an array. When the order does not matter and the names are unique, I prefer using a map, which has less markup because it doesn't need the "name" label for each bone.
{
"bones": [
{
"name": "leg right",
"rotate": [
{ "time": 0, "angle": 26.88 },
{ "time": 0.5, "angle": 13.79 },
{ "time": 0.6666, "angle": 26.88 }
],
}
]
}
사용자 아바타
Nate

Nate
  • 전체글: 11857


다시 돌아감: Editor