Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
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&nbsp;</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>&nbsp; &nbsp; 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>&nbsp; &nbsp; var client =3D new RestClient(this.Context=
.Request.Url.ToString());</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &n=
bsp; var request =3D new RestRequest("SugarTown/Posts", Method.GET);</div><=
div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; request.AddHeader("Accept",=
 "application/json");</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp;=
 var response2 =3D client.Execute&lt;List&lt;Post&gt;&gt;(request);</div><d=
iv><br></div><div><br></div><div>**JSON**</div><div><br></div><div>&nbsp; &=
nbsp; [</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nb=
sp; &nbsp; &nbsp; &nbsp; "Id": "posts/1",</div><div>&nbsp; &nbsp; &nbsp; &n=
bsp; &nbsp; &nbsp; "Title": "testes jkl",</div><div>&nbsp; &nbsp; &nbsp; &n=
bsp; &nbsp; &nbsp; "DateCreated": "/Date(-59011459200000)/",</div><div>&nbs=
p; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Body": "&lt;p&gt;&lt;strong&gt;sccsd=
c&lt;/strong&gt;&lt;/p&gt;",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp; "Tags": null</div><div>&nbsp; &nbsp; &nbsp; &nbsp; },</div><div>&nbsp=
; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp=
; "Id": "posts/33",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Ti=
tle": "yeah baby",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Dat=
eCreated": "/Date(-59011459200000)/",</div><div>&nbsp; &nbsp; &nbsp; &nbsp;=
 &nbsp; &nbsp; "Body": "&lt;p&gt;&lt;span style=3D\"text-decoration: underl=
ine;\"&gt;&lt;strong&gt;jkljk jklj lkjkl kj&amp;nbsp;&lt;/strong&gt;&lt;/sp=
an&gt;&lt;/p&gt;\r\n&lt;ol&gt;\r\n&lt;li&gt;&lt;strong&gt;&lt;span style=3D=
\"text-decoration: underline;\"&gt;,lk&lt;/span&gt;&lt;/strong&gt;&lt;/li&g=
t;\r\n&lt;li&gt;&lt;strong&gt;&lt;span style=3D\"text-decoration: underline=
;\"&gt;98&lt;/span&gt;&lt;/strong&gt;&lt;/li&gt;\r\n&lt;/ol&gt;",</div><div=
>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Tags": [</div><div>&nbsp; &nbsp=
; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "asd",</div><div>&nbsp; &nbsp; =
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "qwe",</div><div>&nbsp; &nbsp; &n=
bsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "fgh",</div><div>&nbsp; &nbsp; &nbs=
p; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "jh"</div><div>&nbsp; &nbsp; &nbsp; &=
nbsp; &nbsp; &nbsp; ]</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nb=
sp; &nbsp; ]</div><div><br></div><div>**Model**</div><div><br></div><div>&n=
bsp; &nbsp; public class Post</div><div>&nbsp; &nbsp; {</div><div>&nbsp; &n=
bsp; &nbsp; &nbsp; public string Id { get; set; }</div><div>&nbsp; &nbsp; &=
nbsp; &nbsp; public string Title { get; set; }</div><div>&nbsp; &nbsp; &nbs=
p; &nbsp; public DateTime DateCreated { get; set; }</div><div>&nbsp; &nbsp;=
 &nbsp; &nbsp; public string Body { get; set; }</div><div>&nbsp; &nbsp; &nb=
sp; &nbsp; public Collection&lt;string&gt; Tags { get; set; }</div><div>&nb=
sp; &nbsp; }</div>
------=_Part_1174_7612403.1345048576467--

------=_Part_1173_28366096.1345048576466--