bacteriaman
Member
I'm trying to produce the following encoded JSON in order to POST scores to a RESTful service:
I'm very close using the following DS functions:
This outputs the following:
The only thing different is the array (square brackets) wrapping the object (curly brackets) for the two field references:
This presumably requires another type of nesting, but the syntax eludes me. Any advice is greatly appreciated.
Note the above GML has not been optimized. Perhaps there's a more efficient way to go about it (?)
Code:
{
"_links": {
"type": {
"href": "http://example.com"
}
},
"title": {"value": "Score 100 by John"},
"field_game_reference": [{"target_id": "2"}],
"field_player_reference": [{"target_id": "3"}],
"field_score_points": {"value": "100"}
}
Code:
var href = ds_map_create();
ds_map_add(href, "href", "http://example.com");
var type = ds_map_create();
ds_map_add_map(type, "type", href);
var map = ds_map_create();
ds_map_add_map(map, "_links", type);
var item = ds_map_create();
ds_map_add(item, "value", "Score 100 by John");
ds_map_add_map(map, "title", item);
var item = ds_map_create();
ds_map_add(item, "target_id", "2");
ds_map_add_map(map, "field_game_reference", item);
var item = ds_map_create();
ds_map_add(item, "target_id", "3");
ds_map_add_map(map, "field_player_reference", item);
var item = ds_map_create();
ds_map_add(item, "value", "100");
ds_map_add_map(map, "field_score_points", item);
ds_map_destroy(item);
ds_map_destroy(href);
ds_map_destroy(type);
ds_map_destroy(map);
Code:
{
"field_player_reference": { "target_id": "3" },
"_links": {
"type": {
"href": "http:\/\/example.com"
}
},
"title": { "value": "Score 100 by John" },
"field_game_reference": { "target_id": "2" },
"field_score_points": { "value": "100" }
}
Code:
"field_game_reference": [{"target_id": "2"}],
"field_player_reference": [{"target_id": "3"}],
Note the above GML has not been optimized. Perhaps there's a more efficient way to go about it (?)