我有这个JSON字符串
[ \"postal_code\" ]
我的枚举定义:
[DataContract]
public enum MyEnum
{
[EnumMember(Value = "postal_code")]
PostalCode,
}
这是我到目前为止所做的:
byte[] byteArray = Encoding.ASCII.GetBytes(jsonString);
MemoryStream outputStream = new MemoryStream(byteArray);
DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(MyEnum[]));
MyEnum[] myEnum = (MyEnum[]) dataContractJsonSerializer.ReadObject(outputStream);
outputStream.Close();
//return myEnum ;
到达ReadObject行时出错
System.FormatException: Input string was not in the correct format: nDigits == 0.
如何正确地将JSON字符串反序列化为MyEnum?
我也想避免使用JSON.Net。我想要使用DataContractJsonSerializer。