0

I have a function that receive a JObject, and in one case the Json that I receive are this:

{}

and I was trying to manage with this:

 public void GetSomeJson(JObject request)
    {
          if (request==JObject.Parse("{}"))
              throw new ArgumentNullException("The request are null");
          //more stuff
    }

In this way doesn't work, and jump the condition, any idea to recognize the Json received is null or blank?

  • possible duplicate of [Comparing objects](http://stackoverflow.com/questions/4436299/comparing-objects) – Marc B Sep 09 '14 at 22:02
  • This is not a duplicate (of that particular question, anyway). The answers to that question will not help OP with this question. – cdhowie Sep 09 '14 at 22:06

2 Answers2

2

JObject is a container for properties and implements IDictionary<string, JToken> to access them, so this would test if an object has zero properties:

if (request.Count == 0) { /* The object is empty */ }
cdhowie
  • 158,093
  • 24
  • 286
  • 300
1
public void GetSomeJson(JObject request)
    {
            if ( request != null && request.Count == 0 ) 
              throw new ArgumentNullException("The request are null");

    }
codebased
  • 6,945
  • 9
  • 50
  • 84