I am parsing some Json data that Contains Json objects as
After converting it to c# classes , code converted as :
public class Data
{
public List<Items> photos { get; set; }
}
public class Items
{
public string __invalid_name__3 { get; set; }
public string __invalid_name__0 { get; set; }
public string __invalid_name__2 { get; set; }
}
This data won't deserialize properly . I have tried both Jsoncovert as well as DataContract deserializer.
So I took
List<Items> as List<dynamic>.
But the problem is keys name are still as "0" , "1" and this won't be able to bind to my xaml UI end.
Is there any way to bind this dynamic data to UI?
Using the DataContractJsonSerializer you can set the Name property on your DataMemberAttributes to serialize the object with different names than the names of your properties in C#:
[DataContract]
public class Data
{
[DataMember]
public List<Items> photos { get; set; }
}
[DataContract]
public class Items
{
[DataMember(Name = "3")]
public string Three { get; set; }
[DataMember(Name="0")]
public string Zero { get; set; }
[DataMember(Name = "2")]
public string Two { get; set; }
}
public static void TestJson()
{
var json = "{\"photos\":[{\"0\":\"some data\",\"2\":\"other data\",\"3\":\"another data\"}]}";
var serializer = new DataContractJsonSerializer(typeof(Data));
Data data = serializer.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(json))) as Data;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments