Welcome to WebmasterWorld Guest from 54.144.107.83

Forum Moderators: ocean10000

Message Too Old, No Replies

Can't process json data

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

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


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?
4:33 pm on Nov 15, 2013 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:852
votes: 0


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