나는 내가 얻는 Json을 직렬화 해제하는 데 어려움을 겪고 있습니다.
다음과 같이 보입니다.
{
"seq": "13-g1AAAACLeJz",
"id": "c32b670-37899h8c545",
"changes": [
{
"rev": "9-68joc97b73df883a"
}
]
}
{
"seq": "15-g1AAAACLeJzLYWB-w",
"id": "f73huvh3-of38j8fh",
"changes": [
{
"rev": "4-10516b0f3"
}
],
"deleted": true
}
{
"seq": "16-g1AAAACL4eJzL",
"id": "M.Mustermann",
"changes": [
{
"rev": "388-e6d350281"
}
],
"deleted": true
}
{
"seq": "17-g1AAAACLr43_Q",
"id": "f8h83hf-34f8h",
"changes": [
{
"rev": "4-773re8f44e"
}
],
"deleted": true
}
{
"seq": "18-g1AAwe_g",
"id": "ewf/34r",
"changes": [
{
"rev": "9-wehch87ewc"
}
],
"deleted": true
}
{
"last_seq": "21-g1AA8wd998rAQ",
"pending": 0
}
내 모델 :
public class Root {
public List<Result> results { get; set; }
public string last_seq { get; set; }
public int pending { get; set; }
}
public class Result
{
public string seq { get; set; }
public string id { get; set; }
public List<Change> changes { get; set; }
public bool? deleted { get; set; }
}
public class Change
{
public string rev { get; set; }
}
찾은 모든 솔루션을 시도했지만 아무것도 작동하지 않지만 여전히 다음 예외가 발생합니다.
Newtonsoft.Json.JsonReaderException : JSON 콘텐츠 읽기를 마친 후 추가 텍스트가 발견되었습니다 : {. 경로 '', 줄 2, 위치 0. Newtonsoft.Json.JsonTextReader.Read ()
내가 시도한 것 :
dynamic array = JsonConvert.DeserializeObject<Root>(json);
Root jsonObject = JsonConvert.DeserializeObject<Root>(json);
var jsonObject = JsonConvert.DeserializeObject<List<Root>>(json);
당신이 가진 것은 일련의 JSON 문서가 모두 함께 붙어 있습니다. 또한 더 어색하게 만들기 위해 마지막 것은 나머지와 다릅니다. 따라서 모든 개체를 수동으로 구문 분석하고 어떤 종류의 개체가 있는지 확인해야합니다. JsonReader.SupportMultipleContent
속성 을 사용할 수 있습니다 . 예를 들면 다음과 같습니다.
//Somewhere to keep the parsed results
var results = new List<Result>();
Root root = null;
var serializer = new JsonSerializer();
using (var stringReader = new StringReader(Json))
using (var jsonReader = new JsonTextReader(stringReader))
{
//Make sure the JsonReader knows we have multiple documents
jsonReader.SupportMultipleContent = true;
while (jsonReader.Read())
{
//Read in the next document
var nextObject = JObject.ReadFrom(jsonReader);
//Determine if we are on the last item or not
if(nextObject["last_seq"] != null)
{
root = nextObject.ToObject<Root>();
}
else
{
results.Add(nextObject.ToObject<Result>());
}
}
}
//Store the results in the root object since this is how your classes have been structured
if(root != null)
{
root.results = results;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다