이 같다, 그러나 나는 그렇게 쉽게 해야 한다고 할 때 발생하는 idfsysobject. 내가 데즈리얼리즈 일부 간단한 JSON 붙여넣습니다 관리됨 유형:. 예외적으로:
>. 미싱메토드렉세페시옹 >. # 39, & # 39 의 System.String& 정의된 문자용 파라메트리스 구성자를 없습니다.
한편, I& 시스템.슬링 파라메트리스 구성자를 것은 없는지, 왜 이 문제에 대해 # 39 m not 선택해제합니다 할 수 있다.
수행하는 코드는 역직렬화를 입니다.
using System.Web.Script.Serialization;
private static JavaScriptSerializer serializer = new JavaScriptSerializer();
public static MyType Deserialize(string json)
{
return serializer.Deserialize<MyType>(json);
}
내 유형은 대략:
public class MyType
{
public string id { get; set; }
public string type { get; set; }
public List<Double> location { get; set; }
public Address address { get; set; }
public Dictionary<string, string> localizedStrings { get; set; }
}
다른 class 를 사용할 수 있습니다 주소:
public class Address
{
public string addressLine { get; set; }
public string suite { get; set; }
public string locality { get; set; }
public string subdivisionCode { get; set; }
public string postalCode { get; set; }
public string countryRegionCode { get; set; }
public string countryRegion { get; set; }
}
{
"id": "uniqueString",
"type": "Foo",
"location": [
47.6,
-122.3321
]
"address": {
"addressLine": "1000 Fourth Ave",
"suite": "en-us",
"locality": "Seattle",
"subdivisionCode": "WA",
"postalCode": "98104",
"countryRegionCode": "US",
"countryRegion": "United States"
},
"localizedStrings": {
"en-us": "Library",
"en-ES": "La Biblioteca"
}
}
저도 그냥 내 JSON 같은 경우에도 예외가 있다.
{
"id": "uniquestring"
}
왜 아무도 수 말해보게나 파라메트리스 구성자를 시스템.슬링 필요하지?
어떤 이는 내가 경식도 동일한 문제가 해결되었습니다.
건배!
//Deserializing Json object from string
DataContractJsonSerializer jsonObjectPersonInfo =
new DataContractJsonSerializer(typeof(PersonModel));
MemoryStream stream =
new MemoryStream(Encoding.UTF8.GetBytes(userInfo));
PersonModel personInfoModel =
(PersonModel)jsonObjectPersonInfo.ReadObject(stream);