Good morning,
I studied more in the library and get what I wanted.
What I really needed was to parse from one json to another json and gather its information.
The json: players_tree is uploaded only once into a very big variable and then disappears like magic.
from this:
Code:
{"1":{"id":3,"nickname":"AMGShowtime","photo":"https:\/\/avatars.steamstatic.com\/55a6e8f6a6e0eb9b26ed37312fd5e67f8b9f4ca8_full.jpg"},"2":{"id":null,"nickname":null,"photo":null},"3":{"id":null,"nickname":null,"photo":null},"4":{"id":null,"nickname":null,"photo":null},"5":{"id":null,"nickname":null,"photo":null},"6":{"id":null,"nickname":null,"photo":null},"7":{"id":null,"nickname":null,"photo":null},"8":{"id":null,"nickname":null,"photo":null},"9":{"id":null,"nickname":null,"photo":null},"10":{"id":null,"nickname":null,"photo":null}}
I parsed every first json object, 1.2.3... to 10 and then his value and then I gathered the value from the last object.
this is the code I've used for this operation
Code:
new
JSON:object = json_parse(players_tree, false),
JSON:value
new count = json_object_get_count(object);
new key[200]; //stores key name
new num;
for (new i = 0; i < count; i++)
{
value = json_object_get_value_at(object, i);
num = json_object_get_number(value, "id", true);
server_print("ID: %d", num);
json_object_get_string(value, "nickname", key, charsmax(key), true);
server_print("Nickname: %s", key);
json_object_get_string(value, "photo", key, charsmax(key), true);
server_print("Photo: %s", key);
}
json_free(value);
json_free(object);
}
Output:
Code:
ID: 3
Nickname: AMGShowtime
Photo: https://avatars.steamstatic.com/55a6e8f6a6e0eb9b26ed37312fd5e67f8b9f4ca8_full.jpg
ID: 0
Nickname:
Photo:
ID: 0
Nickname:
Photo:
ID: 0
Nickname:
Photo:
ID: 0
Nickname:
Photo:
ID: 0
Nickname:
Photo:
ID: 0
Nickname:
Photo:
ID: 0
Nickname:
Photo:
ID: 0
Nickname:
Photo:
ID: 0
Nickname:
Photo:
Sorry, for the topic, it was night and my brain was dying slowly and slowly.
I hope community will find this helpful.
Quote:
Originally Posted by fysiks
- I don't see any JSON parsing going on in your AMX Mod X code and you never mentioned what you tried or showed your code (how can we help you with your JSON code if you don't post your JSON code?).
- More importantly, why would you be trying to waste significant processing time on the game server to parse JSON when you can properly store this data in the database (since it's well suited for a table itself) and just read it like you would with a normal query?
|
I mean, I don't know any way how I can store all the data, only to create separate columns, like p, 1,2,3... and so on. But I don't know, JSON comes so handy for my page, and now I needed to parse the value and also get the steamid from another json.
)
Upper was just one of the others that will come.
__________________