check key/node exists in json/xml string
sometimes the key/node doesn't exists in the json/xml string, t开发者_如何学Chis would return error if we try to access them. How can I check if the JObject that contains that json string whether or not it has that key/node? Something like this: C# Treeview checking if node exists but there is no ContainsKey method in VS wp7 express.
What method/class I use to check whether the key/node exists or not in the xml/json?
You could validate the response against a schema (XML or JSON) which requires the node to exist as part of the contract. Then if your XML validates you'll know that its ok.
Might be clearer and more efficient than going through the content looking for it with a custom piece of code.
I didn't try, but I think it works. If you use the XDocument class to get the xml data, you can call the Nodes() method that returns a collection. For example:
XDocument xDoc = ...
xDoc.Nodes().Contains(...)
精彩评论