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.

4

1 回答 1

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.

于 2012-02-11T04:37:25.383 回答