c# - JSON Cannot Deserialize JSON array into type -
i maintain having issues trying json deserialize, after trying multiple approaches.
here json returned web service:
[ { "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 <sup class='crossreference' value='(<a href=\"#cunique-id-23240a\" title=\" a\">a<\/a>)'>(<a href=\"#cunique-id-23240a\" title=\" a\">a<\/a>)<\/sup>meek, <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 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 hunger , <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, shall 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 <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, 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 <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, <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 told disciples <sup class='crossreference' value='(<a href=\"#cunique-id-24294a\" title=\" a\">a<\/a>)'>(<a href=\"#cunique-id-24294a\" title=\" a\">a<\/a>)<\/sup>have boat ready him because of crowd, lest <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" ] } ] } ]
very ugly know. unfortunately else's web service, there isn't much can do. i've been messing around c# model class , can't quite seem work.
calling method:
2013-02-08 20:08:32.768 versesios[36931:c07] unhandled managed exception: cannot deserialize json array type 'verses.core.biblegatewayverses'. (newtonsoft.json.jsonserializationexception) @ newtonsoft.json.serialization.jsonserializerinternalreader.ensurearraycontract (system.type objecttype, newtonsoft.json.serialization.jsoncontract contract) [0x00000] in <filename unknown>:0 @ 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 @ 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 @ newtonsoft.json.serialization.jsonserializerinternalreader.createvaluenonproperty (newtonsoft.json.jsonreader reader, system.type objecttype, newtonsoft.json.serialization.jsoncontract contract) [0x00000] in <filename unknown>:0 @ newtonsoft.json.serialization.jsonserializerinternalreader.deserialize (newtonsoft.json.jsonreader reader, system.type objecttype) [0x00000] in <filename unknown>:0 @ newtonsoft.json.jsonserializer.deserializeinternal (newtonsoft.json.jsonreader reader, system.type objecttype) [0x00000] in <filename unknown>:0 @ newtonsoft.json.jsonserializer.deserialize (newtonsoft.json.jsonreader reader, system.type objecttype) [0x00000] in <filename unknown>:0 @ newtonsoft.json.jsonconvert.deserializeobject (system.string value, system.type type, newtonsoft.json.jsonserializersettings settings) [0x00000] in <filename unknown>:0 @ newtonsoft.json.jsonconvert.deserializeobject[biblegatewayverses] (system.string value, newtonsoft.json.jsonserializersettings settings) [0x00000] in <filename unknown>:0 @ newtonsoft.json.jsonconvert.deserializeobject[biblegatewayverses] (system.string value) [0x00000] in <filename unknown>:0 @ verses.core.biblegateway+response.getversetext (system.string requesturl) [0x00047] in /users/pierceboggan/desktop/verses/verses.core/verses.core/web services/biblegateway.cs:111 @ verses.core.biblegateway.getversetext (system.string searchkeywords) [0x00012] in /users/pierceboggan/desktop/verses/verses.core/verses.core/web services/biblegateway.cs:43
model class:
[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; }
i've used tools such json2csharp.com , generate same thing. i've toyed around using arrays instead of list, no avail. additionally, i've tried replacing footnotes list type object (as recommended json2sharp).
any help appreciated.
your json info wrapped in array, need deserialize array of type
jsonconvert.deserializeobject<biblegatewayverses[]>(jsondata);
hope helps
c# json json.net
No comments:
Post a Comment