Search Results

Search found 1 results on 1 pages for 'user2539667'.

Page 1/1 | 1 

  • Deserialization of JSON object by using DataContractJsonSerializer in C#

    - by user2539667
    enter code hereI'm sure this question has been asked over and over again, but for some reason, I still can't manage to get this to work. I want to deserialize a JSON object that contains a single member; a string array: [{"idTercero":"cod_Tercero"}] This is the class that I'm trying to deserialize into: [DataContract] public class rptaOk { [DataMember] public string idTercero { get; set; } public rptaOk() { } public rptaOk(string idTercero) { this.idTercero = idTercero; } } This is the method that I try to deserialize: public T Deserialise<T>(string json) { DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(T)); using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(json))) { T result = (T)deserializer.ReadObject(stream); return result; } } And so try to fill the object: rptaOk deserializedRpta = deserializarOk(rpta); But for some reason, this returns "" MessageBox.Show(deserializedRpta.idTercero);

    Read the article

1