Message from discussion
Unable to cast object of type 'RestSharp.JsonArray'
Received: by 10.236.185.194 with SMTP id u42mr12380311yhm.29.1345048578146;
Wed, 15 Aug 2012 09:36:18 -0700 (PDT)
X-BeenThere: restsharp@googlegroups.com
Received: by 10.236.78.164 with SMTP id g24ls3674662yhe.6.gmail; Wed, 15 Aug
2012 09:36:17 -0700 (PDT)
Received: by 10.236.176.103 with SMTP id a67mr3968072yhm.2.1345048577645;
Wed, 15 Aug 2012 09:36:17 -0700 (PDT)
Date: Wed, 15 Aug 2012 09:36:16 -0700 (PDT)
From: Jonathan Channon <jonathan.chan...@gmail.com>
To: restsharp@googlegroups.com
Message-Id: <62ef0738-078d-4fa5-95b3-158338edd3b0@googlegroups.com>
Subject: Unable to cast object of type 'RestSharp.JsonArray'
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_1173_28366096.1345048576466"
------=_Part_1173_28366096.1345048576466
Content-Type: multipart/alternative;
boundary="----=_Part_1174_7612403.1345048576467"
------=_Part_1174_7612403.1345048576467
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
This is probably obviously but I can't see the problem.
Below is my code and JSON. Can anyone point me in the right direction?
The response from RestSharp is throwing the error:
Unable to cast object of type 'RestSharp.JsonArray' to type
'System.Collections.Generic.IDictionary`2[System.String,System.Object]'.
Is it because the Tags on the first JSON data is null?
**Code**
var client = new RestClient(this.Context.Request.Url.ToString());
var request = new RestRequest("SugarTown/Posts", Method.GET);
request.AddHeader("Accept", "application/json");
var response2 = client.Execute<List<Post>>(request);
**JSON**
[
{
"Id": "posts/1",
"Title": "testes jkl",
"DateCreated": "/Date(-59011459200000)/",
"Body": "<p><strong>sccsdc</strong></p>",
"Tags": null
},
{
"Id": "posts/33",
"Title": "yeah baby",
"DateCreated": "/Date(-59011459200000)/",
"Body": "<p><span style=\"text-decoration:
underline;\"><strong>jkljk jklj lkjkl
kj </strong></span></p>\r\n<ol>\r\n<li><strong><span
style=\"text-decoration:
underline;\">,lk</span></strong></li>\r\n<li><strong><span
style=\"text-decoration: underline;\">98</span></strong></li>\r\n</ol>",
"Tags": [
"asd",
"qwe",
"fgh",
"jh"
]
}
]
**Model**
public class Post
{
public string Id { get; set; }
public string Title { get; set; }
public DateTime DateCreated { get; set; }
public string Body { get; set; }
public Collection<string> Tags { get; set; }
}
------=_Part_1174_7612403.1345048576467
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<div>This is probably obviously but I can't see the problem.</div><div><br>=
</div><div>Below is my code and JSON. Can anyone point me in the right dire=
ction?</div><div><br></div><div>The response from RestSharp is throwing the=
error:</div><div><br></div><div> Unable to cast object of typ=
e 'RestSharp.JsonArray' to type 'System.Collections.Generic.IDictionary`2[S=
ystem.String,System.Object]'.</div><div><br></div><div>Is it because the Ta=
gs on the first JSON data is null?</div><div><br></div><div>**Code**</div><=
div><br></div><div> var client =3D new RestClient(this.Context=
.Request.Url.ToString());</div><div> </div><div> &n=
bsp; var request =3D new RestRequest("SugarTown/Posts", Method.GET);</div><=
div> </div><div> request.AddHeader("Accept",=
"application/json");</div><div> </div><div> =
var response2 =3D client.Execute<List<Post>>(request);</div><d=
iv><br></div><div><br></div><div>**JSON**</div><div><br></div><div> &=
nbsp; [</div><div> {</div><div> &nb=
sp; "Id": "posts/1",</div><div> &n=
bsp; "Title": "testes jkl",</div><div> &n=
bsp; "DateCreated": "/Date(-59011459200000)/",</div><div>&nbs=
p; "Body": "<p><strong>sccsd=
c</strong></p>",</div><div> &=
nbsp; "Tags": null</div><div> },</div><div> =
; {</div><div>  =
; "Id": "posts/33",</div><div> "Ti=
tle": "yeah baby",</div><div> "Dat=
eCreated": "/Date(-59011459200000)/",</div><div> =
"Body": "<p><span style=3D\"text-decoration: underl=
ine;\"><strong>jkljk jklj lkjkl kj&nbsp;</strong></sp=
an></p>\r\n<ol>\r\n<li><strong><span style=3D=
\"text-decoration: underline;\">,lk</span></strong></li&g=
t;\r\n<li><strong><span style=3D\"text-decoration: underline=
;\">98</span></strong></li>\r\n</ol>",</div><div=
> "Tags": [</div><div>  =
; "asd",</div><div> =
"qwe",</div><div> &n=
bsp; "fgh",</div><div> &nbs=
p; "jh"</div><div> &=
nbsp; ]</div><div> }</div><div>&nb=
sp; ]</div><div><br></div><div>**Model**</div><div><br></div><div>&n=
bsp; public class Post</div><div> {</div><div> &n=
bsp; public string Id { get; set; }</div><div> &=
nbsp; public string Title { get; set; }</div><div> &nbs=
p; public DateTime DateCreated { get; set; }</div><div> =
public string Body { get; set; }</div><div> &nb=
sp; public Collection<string> Tags { get; set; }</div><div>&nb=
sp; }</div>
------=_Part_1174_7612403.1345048576467--
------=_Part_1173_28366096.1345048576466--