Skip to content
TORNLIFE More

Faction API Call - Members not an array.

Started by Bardicer [553834] on in API Development.

5 replies · 227 views · thread synced · 10 days ago · View on torn.com
About this thread

Posts archived: 6 / 6 posts (100%) · the total is Torn's reply count + the opening post at the last fetch

Counted by TornLife from the archived posts.

Archived posts
6
Discussion span
→
People posting
3
Likes on archived posts
6
Authority score
52 / 100
Historical score
24 / 100
Story score
31 / 100
Engagement score
53 / 100
Bardicer [553834]
When calling the API for faction -
https://api.torn.com/faction/?selections=&key=[API-KEY] - I notice the members are not being returned as an array. The prettified result looks like it would be an array of objects, but it's actually not, as there are no square/array brackets.


For clarification/context purposes, I'm trying to serialize it using NewtonSoft.Json in dotnet if that's any help. I can deserialize it as a simple "object" type, but this would require using reflection to iterate over the properties to parse it out which would be more inefficient than being able to declare it as an array.

Are faction members intentionally not being returned as an array in the json?
Mephiles [2087524]
Well Torn is infamous with using IDs as keys in objects. We had the discussion when deciding on what format to use for YATA's database. As the logical thing is to use an ARRAY of OBJECTS. But Torn is known for using OBJECTS in OBJECTS with IDs as keys. IDs being user IDs, item IDs or transaction IDs.

So if you are asking if it should be an ARRAY then by common logic "yes", but by the way Torn has done things then "no".
Stiny [992186]
My personal solution for this was to map everything back into a dictionary.
The second iteration I made was in the JSON deserializer which upon seeing this kind of data structure, would take the outer identifier and add it to the internal object, and then return everything as an array.
Instead of having
"1": { ... } it would be [{ "id" : "1" ... }]