웹 요청을 통해 온라인에서 검색 한 JSON 데이터 문자열이 있습니다. 문자열을 파싱하고 데이터를 작동하지 않는 데이터 구조에 매핑하려고합니다. 이전에 다른 매핑에도 이전과 같은 방법을 사용했습니다.JSON 형식 데이터 비 직렬화
public class ParsePlayerInfo
{
private PlayerClass playerInfo;
public PlayerClass parse(string stringToParse)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
if ((stringToParse != null) && (stringToParse.Length > 0))
{
this.playerInfo = serializer.Deserialize<PlayerClass>(stringToParse);
}
return this.playerInfo;
}
}
이 :
{"Item":{"FirstName":"Antônio","LastName":"da Silva","CommonName":null,"Height":"175","DateOfBirth":{"Year":"1978","Month":"6","Day":"13"},"PreferredFoot":"Left","ClubId":"1825","LeagueId":"20","NationId":"54","Rating":"70","Attribute1":"53","Attribute2":"68","Attribute3":"74","Attribute4":"73","Attribute5":"55","Attribute6":"56","Rare":"1","ItemType":"PlayerM"}}
이 문자열을 구문 분석하는 내 클래스 :하지만이 특별한 경우에, 그것은
이
가 검색됩니다 내 JSON 형식의 문자열입니다 .. 작동하지 않습니다 0 :이 playercontent의 내 수업이public class PlayerClass
{
public PlayerClass()
{
this.Player = new PlayerContents();
}
public PlayerContents Player { get; set; }
}
입니다 : 내 플레이어의 클래스입니다
public class PlayerContents
{
public PlayerContents()
{
string str;
this.ItemType = str = "";
this.Rare = str = str;
this.Attribute6 = str = str;
this.Attribute5 = str = str;
this.Attribute4 = str = str;
this.Attribute3 = str = str;
this.Attribute2 = str = str;
this.Attribute1 = str = str;
this.Rating = str = str;
this.NationId = str = str;
this.LeagueId = str = str;
this.ClubId = str = str;
this.PreferredFoot = str = str;
this.Height = str = str;
this.CommonName = str = str;
this.FirstName = this.LastName = str;
this.DateOfBirth = new DOB();
}
public string Attribute1 { get; set; }
public string Attribute2 { get; set; }
public string Attribute3 { get; set; }
public string Attribute4 { get; set; }
public string Attribute5 { get; set; }
public string Attribute6 { get; set; }
public string ClubId { get; set; }
public string CommonName { get; set; }
public DOB DateOfBirth { get; set; }
public string FirstName { get; set; }
public string Height { get; set; }
public string ItemType { get; set; }
public string LastName { get; set; }
public string LeagueId { get; set; }
public string NationId { get; set; }
public string PreferredFoot { get; set; }
public string Rare { get; set; }
public string Rating { get; set; }
}
편집 :
이 내 DOB 클래스입니다 :
public class DOB
{
public DOB()
{
this.Year = this.Month = this.Day;
}
public string Day { get; set; }
public string Month { get; set; }
public string Year { get; set; }
}
어떤 아이디어?
당신이 어떤 문제가 있습니까? 무엇이 효과가 없는지 설명하지 않고도 도움을주는 것은 어렵습니다. 특히 접근 방식이 "일반적으로 효과가있는 경우"특히 그렇습니다. 그 시간대와 다르게 무엇을 했습니까? –
DOB 클래스 란 무엇입니까? 왜'DateTime'을 사용하지 않습니까? – andri
@RuneFS 웹 서비스를 실행하고 JSON 형식의 데이터를 검색하고 javascriptserializer를 사용하여 deserialize하는 동일한 프로그램 흐름 .. – faizanjehangir