Showing Posts For Cavnapper.4760:

How to deserialize "event_details" in C#?

in API Development

Posted by: Cavnapper.4760

Cavnapper.4760

Thank you very much guys.

I’ve found a solution. I just switched from DataContractJsonSerializer to JSON.NET:
http://james.newtonking.com/pages/json-net.aspx

That works with Dictionary<string, EventDetails> as well as with Dictionary<Guid, EventDetails> and is very comfortable to use.

Although it works now, you awakened that fire in my mind that challenges me to work on my knowledge about serialization/deserialization and to implement an own JSON serializer/deserializer in the future. Probably during my studies in computer science, which begins in October :-)

How to deserialize "event_details" in C#?

in API Development

Posted by: Cavnapper.4760

Cavnapper.4760

@LadyRhonwyn
I tried out that Dictionary<string, EventDetails>, but it doesn’t work too. Maybe I’m doing something wrong. My C# types in attachments.

To avoid confusion: I know that there are not all members present yet, but thats not the problem as it works if every event is a type member of the container type (not shown here, it would just replace the dictionary) named with the event id.

I didn’t get any exception. The objects just weren’t created so the method just returned a null reference.

@Heimdall
I guess I DO keep the structure by the approach to represent every event by a member of the container type. As I mentioned, the problem is that there is no json array in event_details.json. Have a look at the attachments.

An array would be indicated by []-brackets.

What do you mean by " use structs and unions by combining them cleverly within an array"?

Attachments:

(edited by Cavnapper.4760)

How to deserialize "event_details" in C#?

in API Development

Posted by: Cavnapper.4760

Cavnapper.4760

Thanks for your reply.

I already tried this out too. But it doesn’t work so far.
(I’m using DataContractJsonSerializer.)

How to deserialize "event_details" in C#?

in API Development

Posted by: Cavnapper.4760

Cavnapper.4760

Hey guys,

I’m a beginner in programming C#/.NET. I’m currently working on a library that makes the GW2-API usable in a .NET environment.
My objective is not to publish it (neither it gets finished anytime in the future). It is just some kind of training and should help me to improve my skills.

At the Moment I’m trying to deserialize the “event_details.json”-data. I actually got that working but, if I strictly follow the structure of the json-data, I have to create one type member in C# per ingame event in the container type. Since there are 1667 different events in GW2, that seems a bit inconvenient to me.

If that was another array just like in “events.json”, with the event_id as a type member of the event type, I could map this to a List<> too. But all events seem to be a distinct member of the container, although they all have the same members.

Does anyone have an idea how to deserialize “event_details.json” without the need to create a container-type member for every event?
AFAIK there is no possibility in C# to dynamically name variables at runtime.

Thanks in advance!

(edited by Cavnapper.4760)