0

maybe this was asked somewhere before, but I don't know how to search for my problem. I'm using a WebAPI to verify licenses. From this API I get the return JSON string in follwing format.

string json = "[{"status":"error","status_code":"e002","message":"Invalid licence key"}]"

This is my serializer

using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(json)))
{
                DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(ActivationResponseWooSl));
                ActivationResponseWooSl ar = (ActivationResponseWooSl)js.ReadObject(ms);
}

Now my questions is, how must the "ActivationResponseWooSl" class look like so that the serializer can convert it?

Any help is highly appreciated!

For now it looks like that (what's not workiing):

[DataContract]
public class ActivationResponseWooSl
{
    [DataMember(Name = "status")]
    public string Status { get; set; }

    [DataMember(Name = "status_code")]
    public string ErrorCode { get; set; }

    [DataMember(Name = "message")]
    public string ErrorMessage { get; set; }
}

However when I serialize my json string, all properties are "null".

1 Answer 1

1

Your class is correct. Your JSON is an array of object.

Try

DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(ActivationResponseWooSl[]));
var arr = (ActivationResponseWooSl[])js.ReadObject(ms);
Sign up to request clarification or add additional context in comments.

2 Comments

That was fast and the perfect solution! Thank you so much for your quick support :)
@AndreasReitberger Glad to help you :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.