Southclaws / pawn-json

JSON for Pawn.
MIT License
21 stars 10 forks source link

JSON_ArrayAppend example #10

Open jusTcrmp opened 2 years ago

jusTcrmp commented 2 years ago

Hello! Can you give me example for function JSON_ArrayAppend?

i need to make this json: {"items": [{"index": 0, "name": "Nissan GT-R"}, {"index": 1, "name": "Cadillac Escalade"}]}

buy i dont know how i can add objects to array with cycle

Southclaws commented 2 years ago

I had to look up the source code as I forgot what it even does, and there are no examples either, sorry!

JSON_ArrayAppend takes three arguments, the first is an object node ID, the second is a key within that object which contains an array node and the third is another node to push into that array (not concatenate).

So it would look something like this I think:

new Node:arr = JSON_Array(
    JSON_Int(1),
    JSON_Int(2)
);

new Node:a = JSON_Object(
    "key1", arr
);

JSON_ArrayAppend(a, "key1", JSON_Int(3));

// { "key1": [ 1, 2, 3 ] }
jusTcrmp commented 2 years ago

thank you

jusTcrmp commented 2 years ago

i think you can add this to json.inc