tags:

views:

223

answers:

1

hi, I am using twitter api, and the response i get is in Json format. when i parse json using C# so the value of profile_image_url does not contain proper url, this url is absolutly fine in the response, but after parsing the response i get the following url. how do i remove backslashes?

http:\/\/a1.twimg.com\/profile_images\/700049686\/14_normal.jpg

+2  A: 

You can remove backslashes using the Replace function:

url = url.Replace("\\", "")

But perhaps you ought to spend some time working out how those backslashes got there in the first place. It sounds like you aren't parsing the JSON correctly. What parser are you using?

Mark Byers
+1 - And to venture a guess at the answer to your question; I reckon there's no real JSON parser being used here at all - I can't imagine anything that calls itself a JSON 'parser' failing to read ecape sequences in strings.
Andras Zoltan
I am using JsonArray class to parse the json like this: JsonValue jasonValue = JsonArray.Parse(json); JsonValue results = jasonValue["results"]; List<Artist> artists = new List<Artist>(); foreach (JsonObject jsonArtist in results) { Artist artist = new Artist(); artists.CreatedByProfileImageUrl = jsonArtist["profile_image_url"].ToString(); artists.Add(artists); }
Zain Shaikh
Try the DataContractJSONSerializer in System.Runtime.Serialization - that does a much beter job of serializing JSON - arrays can be tricky, but I can usually get it to behave with ayny format I throw at it.
Andras Zoltan
yeah, I also wanted to use DataContractJSONSerializer, but I'd to create classes for this separalty. and i did not want to create new classes, I wanted to use existing classes, therefore using the foreach loop to fill each property of my class.
Zain Shaikh
@Mark, thanks, your solution works, but i am sure there is something wrong with the parsor, I'd need to use thrid party parser if i find any good. thanks anyways. :)
Zain Shaikh