Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

Newtonsoft Jobject null as API parameter

$
0
0

I have a web api function that is receiving a json value and converting it to a jObject like this:

[HttpPost]
public IHttpActionResult AddWalletItem(JObject InsertParams)
{
         ... //code that does stuff
}

The jObject is just fine as long as the json I pass to it is well formed.  I.e.:

{"CustName": "Joe Schmoe","UseType": "R","ModifiedByUserId": 1234567
}

But if I take off one of the property values like this:

{"CustName": "Joe Schmoe","UseType": "R","ModifiedByUserId":
}

The insertParams variable will be null.  

So I'm wondering if I'm using the right newtonsoft object for this or should I be using something else?  What I'm thinking is that it's possible the users could throw a malformed json object at us and I'd want to give them a specific error message, rather than just say "your json is bad."

Any ideas anyone?


Viewing all articles
Browse latest Browse all 4850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>