0

The answer to this question shows how to load a Json string to a hard-coded class using JavaScriptSerializer. However, the class structure has to be coded, and this looks impractical if you're just interested in a few values, and not interested in parsing the whole string.

Is there something similar to XElement, where I can simply load a XML string and then use xElement.Elements("Items").Select( el => el.Elements("Title")) in order to list the title of all items, for example. I prefer if I can use pure .NET without third-party libraries. It would be nice if I can also linq it like XElement

In case the context is useful, I'm trying to parse the a list of question provided by StackExchange API (json format) to a nicely formatted string, and I only want some infos like title, link, and author.

Community
  • 1
  • 1
Louis Rhys
  • 34,517
  • 56
  • 153
  • 221

1 Answers1

1

It sounds like what you are really asking for is a Linq to JSON adapter. Why be burdened by XML if you don't need to be? JSON is an object serialization format, not an XML format, so you should think of it as "How can I use LINQ to Objects with objects from JSON?

A quick google search for "Linq json" turns up several interesting topics. Give it a spin.

dthorpe
  • 35,318
  • 5
  • 75
  • 119
  • mm maybe I didn't explain myself well. I don't want to use XML or XElement, I just want XElement's behaviour where I don't have to create the class definition, and just use string to query the holder object, unlike in the linked question. I'll try to google it. – Louis Rhys Feb 11 '12 at 04:46
  • That's what I said. :> You don't want XElement, you want Linq binding to JSON hydrated objects. – dthorpe Feb 11 '12 at 18:51