다음과 같은 Json 모델이 있습니다.
private class SearchMetadataJson
{
public string entertain { get; set; }
public string master { get; set; }
public string memail { get; set; }
public string key { get; set; }
public (int, string)[] mood { get; set; }
public int? soundnumber { get; set; }
public int? ftv { get; set; }
public int? com { get; set; }
public (int, string)[] sims { get; set; }
public (int, string)[] keysecond { get; set; }
public string popt { get; set; }
public (string, string) syncs { get; set; }
}
다음과 같이 객체를 역 직렬화하려고합니다.
var CommentObj = JsonSerializer.Deserialize<SearchMetadataJson>(CommentAsString);
직렬화 해제하려는 데이터 (일명 "CommentAsString")는 다음과 같습니다.
"{\"entertain\":\"PEG\",\"master\":\"Phos Ent Group\",\"memail\":\"[email protected]\",\"key\":\"Db\",\"mood\":{\"1\":\"TypeA\",\"4\":\"TypeB\",\"5\":\"TypeC\"},\"soundnumber\":\"5\",\"ftv\":\"4\",\"com\":\"3\",\"sims\":{\"1\":\"Band1\",\"2\":\"Band2\"},\"keysecond\":{\"1\":\"KeyWord1\",\"2\":\"KeyWord2\",\"3\":\"KeyWord3\"},\"syncs\":{\"Other pubber\":\"[email protected]\"}}"
문제가 무엇인지 아는 사람이 있습니까?
업데이트
의 정수 CommentAsString
는 변수이며 함수가 호출 될 때마다 달라 지므로 특정 정수의 키 값을 가진 Json 객체를 만들 수 없습니다.
실제 형식화 된 데이터 구조를 살펴 보겠습니다.
{
"entertain":"PEG",
"master":"Phos Ent Group",
"memail":"[email protected]",
"key":"Db",
"mood":{
"1":"TypeA",
"4":"TypeB",
"5":"TypeC"
},
"soundnumber":"5",
"ftv":"4",
"com":"3",
"sims":{
"1":"Band1",
"2":"Band2"
},
"keysecond":{
"1":"KeyWord1",
"2":"KeyWord2",
"3":"KeyWord3"
},
"syncs":{
"Other pubber":"[email protected]"
}
}
이들을 튜플 배열 로 변환하는 것은 드문 일입니다. 겉보기에는 사전이 있습니다.
예
private class SearchMetadataJson
{
public string entertain { get; set; }
public string master { get; set; }
public string memail { get; set; }
public string key { get; set; }
public Dictionary<int,string> mood { get; set; }
public int? soundnumber { get; set; }
public int? ftv { get; set; }
public int? com { get; set; }
public Dictionary<int,string> sims { get; set; }
public Dictionary<int,string> keysecond { get; set; }
public string popt { get; set; }
// public (string, string) syncs { get; set; }
}
마지막 속성이 객체인지 다른 사전인지는 논쟁의 여지가 있습니다.
"syncs":{
"Other pubber":"[email protected]"
}
그러나 나는 당신에게 맡길 것입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다