Ok, first hear me out by looking at this url:
http://api.flickr.com/services/feeds/photos_public.gne?format=json
Notice how the Description string has non-encoded html in it such as <, >, etc.
Here is how I returned my JSON using ASP.NET 3.5 and C#:
context.Response.ContentType = "text/plain";
context.Response.Charset = Encoding.UTF8.ToString();
int i = 1;
List<Product> products = GetTestProducts();
List<CrImageList> imageList = new List<CrImageList>();
foreach(Product p in products)
{
string imageTag = HttpUtility.HtmlEncode(string.Format(@"<img src=""{0}"" alt="""">", ImageUrl(p.Image, false)));
imageList.Add(new CrImageList{ImageTag = imageTag});
i++;
}
string jsonString = imageList.ToJSON();
context.Response.Write(jsonString);
And here is the JSON returned by this code that is called when I hit my .ashx and it calls this code in the method that contains it:
[{"ImageTag":"<img src="http://www.ourdomain.com/image/540.jpg&quot; alt="">"},{"ImageTag":"<img src="http://www.ourdomain.com/image/642.jpg&quot; alt="">"}]
Now how can I get the encoded characters to actually show up as html chars in the text string returned by my JSON?
I want < to show < and so on just like Flickr was able to do in their JSON.
If I take out the HtmlEncode:
string.Format(@"", ImageUrl(p.Image, false));
Then I start to get the /u00 in my string:
[{"ImageTag":"\u003cimg src=\"http://www.xxx.com/cat_image/540.jpg\" alt=\"\"\u003e"},
...
So why doesn't Flickr's JSON return anything but clean html in their description?