0

sometimes the key/node doesn't exists in the json/xml string, this 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?

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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(...)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.