rss and json format
| Comments- | Posted in
- json
- atlas
- asp.net
- aspnet
- rss
- asp.net ajax
- javascript
i was working on a little sample and wanted to make it a bit easier on myself to work with my rss data. my thought was to use the JSON format for the data and that way i could get at the data in super-cool-ajaxy-type ways. what was cool was what i found as i began searching.
ASP.NET Ajax provides a class library to javascript! in System.Web.Script.Serialization.JavascriptSerializer is where you will find your magic. the JavascriptSerializer can be used on anything that uses XmlSerialization. sweet.
so now all i had to do was take my RSS data (already in good xml format) and serialize that to xml. once the rss is in a strongly typed respresentation using XmlSerialization, then i can pass that object to the JavascriptSerializer and voila...json formatted representation.
so my rss:
<?xml version="1.0" encoding="UTF-8"?> <channel>
<title>Method ~ of ~ failed</title> <link>http://timheuer.com/blog/Default.aspx</link>
<description>ramblings from the digital underbelly</description>
<language>en-US</language> <copyright>timheuer</copyright>
<managingEditor>[email protected]</managingEditor>
<generator>Subtext Version 1.9.5.176</generator> ...
becomes:
{"Version":"2.0","Channel":{"Categories":[],"Cloud":null,
"Copyright":"timheuer","Description":"ramblings from the digital underbelly",
"Docs":null,"Generator":"Subtext Version 1.9.5.176", ...
wicked. i put this in an asp.net handler file for me so now i can easily reference some rss data and immediately get back json data to work with, something like:
<script src="http://mysite/rss2json.ashx?u=http://feeds.feedburner.com/timheuer"></script>
you can get an rss serializer with this function built in over at piyush's blog. very cool, now i can move on to my next step...
Please enjoy some of these other recent posts...
Comments