Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a strange problem. I have a Web Api containing a products catalog.
When I load all the products into a datagridview object by usng:
C#
_products = JsonConvert.DeserializeObject<List<Product>>(result.Result);

Everything runs fine. When my result only contains 1 product the above line throws an exception that it cannot set the JSON to an object.
So I then have to use:
C#
Product product = JsonConvert.DeserializeObject<Product>(result.Result);

How to avoid this exception? I now start to deserialize to a List<> object and when the exception occurs I deserialize to the object, clean my list, ad my 1 value and my datagridview shows me desired product.
How to detect the number of items in the JSON string? Any other setting needed?

Regards,

Herman
Posted
Comments
Sergey Alexandrovich Kryukov 16-Apr-15 11:01am    
This is a commercial product with some free version, but not open-source. I see no need to use it, but if you want it, you probably need to address to their customer support. There is open-source JSON.NET, and there is .NET FCL with JSON support.
—SA
Herman<T>.Instance 16-Apr-15 11:07am    
There is no support section on their website.....
Product has MT license, so free for commercial use
Richard Deeming 16-Apr-15 11:30am    
Newtonsoft == JSON.NET :)
http://www.newtonsoft.com/json[^]

Only "JSON.NET Schema" requires a license.
Sergey Alexandrovich Kryukov 16-Apr-15 11:32am    
Is this the same or not: https://json.codeplex.com?
It looks like it was moved from Newtonsoft and because open-source, but Newtonsoft still charges for it a for a commercial product. Is that so?
—SA
Richard Deeming 16-Apr-15 11:36am    
It's the same.

The CodePlex site has a link to the new home on GitHub:
https://github.com/JamesNK/Newtonsoft.Json[^]

The GitHub page links to the home page:
http://www.newtonsoft.com/json[^]

They both link to the blog:
http://james.newtonking.com/[^]

Newtonsoft doesn't charge for JSON.NET, only JSON.NET Schema, which is a separate product.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900