Forum Moderators: open

Message Too Old, No Replies

Can't process json data

         

andrewsmd

11:30 pm on Nov 13, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm trying to parse a simple JSON string
[{"url":"http://loyalty.bosselman.com/Home/tabid/57/Default.aspx","position":"0","roles":"All Users;Administrators;"}]

You can find it here

[loyalty.bosselman.com...]

When I run this code

var baseUrl = "http://loyalty.bosselman.com/DesktopModules/MyServices/API/Welcome/GetMenu?key";

WebClient client = new WebClient();
var data = client.DownloadString(baseUrl);


var obj = JsonConvert.DeserializeObject(data);

JObject job = JObject.Parse(obj.ToString());

foreach (JProperty prop in job.Properties())
{
Response.Write(prop["url"]);
}
I get this error

Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.

If I inspect my obj element it looks like this

"[{\"url\":\"http://loyalty.bosselman.com/Home/tabid/57/Default.aspx\",\"position\":\"0\",\"roles\":\"All Users;Administrators;\"}]"

I'm not sure why the \" are getting in there and obj.replace("\\", ""); does not remove them. What am I doing wrong?

Ocean10000

4:33 pm on Nov 15, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



When you are inspecting the string the \" are seeing are the escaped ". The slash are not actually in the string.