2013-02-09 3 views
4

으로 역 직렬화 할 수 없습니다. 여러 접근 방식을 시도한 후에도이 JSON을 역 직렬화하려는 데 문제가 있습니다.JSON JSON 배열을 유형을

[ 
    { 
     "data":[ 
     { 
      "osis":"Matthew 5:5-8", 
      "content":"<p><span id=\"unique-id-23240\" class=\"text Matt-5-5\"><span class=\"woj\"><sup class=\"versenum\">5\u00a0<\/sup>\u201cBlessed are the <sup class='crossreference' value='(<a href=\"#cunique-id-23240A\" title=\" A\">A<\/a>)'>(<a href=\"#cunique-id-23240A\" title=\" A\">A<\/a>)<\/sup>meek, for they <sup class='crossreference' value='(<a href=\"#cunique-id-23240B\" title=\" B\">B<\/a>)'>(<a href=\"#cunique-id-23240B\" title=\" B\">B<\/a>)<\/sup>shall inherit the earth.<\/span><\/span><\/p> <p><span id=\"unique-id-23241\" class=\"text Matt-5-6\"><span class=\"woj\"><sup class=\"versenum\">6\u00a0<\/sup>\u201cBlessed are those who hunger and <sup class='crossreference' value='(<a href=\"#cunique-id-23241C\" title=\" C\">C<\/a>)'>(<a href=\"#cunique-id-23241C\" title=\" C\">C<\/a>)<\/sup>thirst <sup class='crossreference' value='(<a href=\"#cunique-id-23241D\" title=\" D\">D<\/a>)'>(<a href=\"#cunique-id-23241D\" title=\" D\">D<\/a>)<\/sup>for righteousness, for they shall be satisfied.<\/span><\/span><\/p> <p><span id=\"unique-id-23242\" class=\"text Matt-5-7\"><span class=\"woj\"><sup class=\"versenum\">7\u00a0<\/sup>\u201cBlessed are <sup class='crossreference' value='(<a href=\"#cunique-id-23242E\" title=\" E\">E<\/a>)'>(<a href=\"#cunique-id-23242E\" title=\" E\">E<\/a>)<\/sup>the merciful, for they shall receive mercy.<\/span><\/span><\/p> <p><span id=\"unique-id-23243\" class=\"text Matt-5-8\"><span class=\"woj\"><sup class=\"versenum\">8\u00a0<\/sup>\u201cBlessed are <sup class='crossreference' value='(<a href=\"#cunique-id-23243F\" title=\" F\">F<\/a>)'>(<a href=\"#cunique-id-23243F\" title=\" F\">F<\/a>)<\/sup>the pure in heart, for <sup class='crossreference' value='(<a href=\"#cunique-id-23243G\" title=\" G\">G<\/a>)'>(<a href=\"#cunique-id-23243G\" title=\" G\">G<\/a>)<\/sup>they shall see God.<\/span><\/span><\/p>", 
      "footnotes":[ 

      ], 
      "crossrefs":[ 
       "<li id=\"cunique-id-23240A\"><a href=\"#unique-id-23240\" title=\" Matthew 5:5\">Matthew 5:5<\/a> : <a href=\"\/passage\/?search=Ps 37:11&version=ESV\" data-bibleref=\"Ps.37.11\">Ps. 37:11<\/a><\/li>\n", 
       "<li id=\"cunique-id-23240B\"><a href=\"#unique-id-23240\" title=\" Matthew 5:5\">Matthew 5:5<\/a> : <a href=\"\/passage\/?search=Ps 37:11&version=ESV\" data-bibleref=\"Ps.37.11\">Ps. 37:11<\/a><\/li>\n", 
       "<li id=\"cunique-id-23241C\"><a href=\"#unique-id-23241\" title=\" Matthew 5:6\">Matthew 5:6<\/a> : <a href=\"\/passage\/?search=Ps 42:2, Isa 55:1-Isa 55:2, John 7:37&version=ESV\" data-bibleref=\"Ps.42.2,Isa.55.1-Isa.55.2,John.7.37\">Ps. 42:2; Isa. 55:1, 2; John 7:37<\/a><\/li>\n", 
       "<li id=\"cunique-id-23241D\"><a href=\"#unique-id-23241\" title=\" Matthew 5:6\">Matthew 5:6<\/a> : <a href=\"\/passage\/?search=2Tim 2:22, Matt 6:33&version=ESV\" data-bibleref=\"2Tim.2.22,Matt.6.33\">2 Tim. 2:22; [ch. 6:33]<\/a><\/li>\n", 
       "<li id=\"cunique-id-23242E\"><a href=\"#unique-id-23242\" title=\" Matthew 5:7\">Matthew 5:7<\/a> : <a href=\"\/passage\/?search=Matt 18:33, Matt 25:34-Matt 25:36, Prov 19:17, Luke 6:36, 2Tim 1:16, Heb 6:10&version=ESV\" data-bibleref=\"Matt.18.33,Matt.25.34-Matt.25.36,Prov.19.17,Luke.6.36,2Tim.1.16,Heb.6.10\">ch. 18:33; 25:34-36; Prov. 19:17; Luke 6:36; 2 Tim. 1:16; Heb. 6:10<\/a><\/li>\n", 
       "<li id=\"cunique-id-23243F\"><a href=\"#unique-id-23243\" title=\" Matthew 5:8\">Matthew 5:8<\/a> : <a href=\"\/passage\/?search=Ps 24:4, 2Tim 2:22, 1Pet 1:22&version=ESV\" data-bibleref=\"Ps.24.4,2Tim.2.22,1Pet.1.22\">Ps. 24:4; 2 Tim. 2:22; [1 Pet. 1:22]<\/a><\/li>\n", 
       "<li id=\"cunique-id-23243G\"><a href=\"#unique-id-23243\" title=\" Matthew 5:8\">Matthew 5:8<\/a> : <a href=\"\/passage\/?search=Heb 12:14, 1John 3:2-1John 3:3, Rev 22:4, 1Cor 13:12&version=ESV\" data-bibleref=\"Heb.12.14,1John.3.2-1John.3.3,Rev.22.4,1Cor.13.12\">Heb. 12:14; 1 John 3:2, 3; Rev. 22:4; [1 Cor. 13:12]<\/a><\/li>\n" 
      ] 
     }, 
     { 
      "osis":" Mark 3:9", 
      "content":"<p><span id=\"unique-id-24294\" class=\"text Mark-3-9\"><sup class=\"versenum\">9\u00a0<\/sup>And he told his disciples to <sup class='crossreference' value='(<a href=\"#cunique-id-24294A\" title=\" A\">A<\/a>)'>(<a href=\"#cunique-id-24294A\" title=\" A\">A<\/a>)<\/sup>have a boat ready for him because of the crowd, lest they <sup class='crossreference' value='(<a href=\"#cunique-id-24294B\" title=\" B\">B<\/a>)'>(<a href=\"#cunique-id-24294B\" title=\" B\">B<\/a>)<\/sup>crush him,<\/span><\/p>", 
      "footnotes":[ 

      ], 
      "crossrefs":[ 
       "<li id=\"cunique-id-24294A\"><a href=\"#unique-id-24294\" title=\" Mark 3:9\">Mark 3:9<\/a> : <a href=\"\/passage\/?search=Mark 6:32, Mark 6:45, Mark 8:10&version=ESV\" data-bibleref=\"Mark.6.32,Mark.6.45,Mark.8.10\">ch. 6:32, 45 (Gk.); 8:10 (Gk.)<\/a><\/li>\n", 
       "<li id=\"cunique-id-24294B\"><a href=\"#unique-id-24294\" title=\" Mark 3:9\">Mark 3:9<\/a> : <a href=\"\/passage\/?search=Mark 5:24, Mark 5:31&version=ESV\" data-bibleref=\"Mark.5.24,Mark.5.31\">ch. 5:24, 31<\/a><\/li>\n" 
      ] 
     } 
     ] 
    } 
] 

매우 추한 내가 아는 : 여기

는 웹 서비스에서 반환 된 JSON입니다. 불행히도 다른 사람의 웹 서비스이기 때문에 할 수있는 일이 많지 않습니다. 나는 C# 모델 클래스를 망설 였고 제대로 작동하지 않는 것 같습니다. 메소드 호출

:

2013-02-08 20:08:32.768 VersesiOS[36931:c07] Unhandled managed exception: Cannot deserialize JSON array into type 'Verses.Core.BibleGatewayVerses'. (Newtonsoft.Json.JsonSerializationException) 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureArrayContract (System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract) [0x00000] in <filename unknown>:0 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.Object existingValue, System.String reference) [0x00000] in <filename unknown>:0 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.Object existingValue) [0x00000] in <filename unknown>:0 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract) [0x00000] in <filename unknown>:0 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <filename unknown>:0 
    at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <filename unknown>:0 
    at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <filename unknown>:0 
    at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0 
    at Newtonsoft.Json.JsonConvert.DeserializeObject[BibleGatewayVerses] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0 
    at Newtonsoft.Json.JsonConvert.DeserializeObject[BibleGatewayVerses] (System.String value) [0x00000] in <filename unknown>:0 
    at Verses.Core.BibleGateway+Response.GetVerseText (System.String requestUrl) [0x00047] in /Users/pierceboggan/Desktop/Verses/Verses.Core/Verses.Core/Web Services/BibleGateway.cs:111 
    at Verses.Core.BibleGateway.GetVerseText (System.String searchKeywords) [0x00012] in /Users/pierceboggan/Desktop/Verses/Verses.Core/Verses.Core/Web Services/BibleGateway.cs:43 

모델 클래스 :

[JsonObject(MemberSerialization.OptIn)] 
public class BibleGatewayVerse 
{ 
    [JsonProperty("osis")] 
    public string Reference { get; set; } 
    [JsonProperty("content")] 
    public string Content { get; set; } 
    [JsonProperty("footnotes")] 
    public List<string> Footnotes { get; set; } 
    [JsonProperty("crossrefs")] 
    public List<string> CrossReferences { get; set; } 
} 

[JsonObject(MemberSerialization.OptIn)] 
public class BibleGatewayVerses 
{ 
    [JsonProperty("data")] 
    public List<BibleGatewayVerse> Verses; 
} 

나는 그런 json2csharp.com 같은 도구를 사용했습니다 그리고 그들은 같은 일을 생성합니다. 또한 List 대신 배열을 사용하여 놀았지만 아무 소용이 없습니다. 또한 각주 목록을 type 객체 (json2sharp에서 권장하는 바)로 대체 해 보았습니다.

도움을 주시면 감사하겠습니다.

+0

오류는'EnsureArrayContract '이므로 클래스 레이아웃과 관련이 있는지 의심 스럽습니다. 일반 json 객체로 deserialize하려고 시도 할 수 있습니다. 파서를 트립하는 문자를 식별 할 때까지 텍스트에서 칩이 떨어진다면 실패 할 수 있습니다. deserialize to generic object가 작동하면 클래스 디자인 문제이지만 더 많은 정보를 얻으실 수 있습니다. –

+0

네. 일반 JSON 객체가 실패했습니다. 내가 생각하는 것을보기 위해 조금 더 깊이 들어가야 해. – pierceboggan

답변

7

당신이 유형의 배열에 역 직렬화 할 필요가 귀하의 JSON 데이터를 배열에 싸여

JsonConvert.DeserializeObject<BibleGatewayVerses[]>(jsonData); 

희망이

+1

굉장! 이것은 문제를 해결했습니다! – pierceboggan

0

난 당신이

public class BibleGatewayVerse 
{ 

    [JsonProperty("data")] 
    public Datum[] Data { get; set; } 
} 


public class Datum 
{ 

    [JsonProperty("osis")] 
    public string Osis { get; set; } 

    [JsonProperty("content")] 
    public string Content { get; set; } 

    [JsonProperty("footnotes")] 
    public object[] Footnotes { get; set; } 

    [JsonProperty("crossrefs")] 
    public string[] Crossrefs { get; set; } 
} 
처럼 따라야한다고 생각하는 데 도움이