Click here to Skip to main content
15,885,435 members
Everything / JSON.NET

JSON.NET

JSON.NET

Great Reads

by thangchung
Learn to organize clean architecture to modular patterns
by Graeme_Grant
Working with simple JSON objects and collections to Custom Converters and Transformations into .NET classes - System.Text.Json
by Michael Doleman
A simple DAL with an integrated, lightweight model for database seeding from a JSON source, using the code-first method in Entity Framework.
by Hamid Mosalla
Dynamically building JSON tree for use In JavaScript components using C#

Latest Articles

by Graeme_Grant
How to deserialize very large simple & complex JSON Streams (.NET 6.0 & 7.0)
by Graeme_Grant
Working with simple JSON objects and collections to Custom Converters and Transformations into .NET classes - System.Text.Json
by Graeme_Grant
Working with simple JSON objects and collections to Custom Converters and Transformations into .NET classes - NewtonSoft.Json
by Uladzislau Baryshchyk
Easy way to work with JSON file in C#/.NET

All Articles

Sort by Score

JSON.NET 

22 Oct 2017 by thangchung
Learn to organize clean architecture to modular patterns
31 Oct 2022 by Graeme_Grant
Working with simple JSON objects and collections to Custom Converters and Transformations into .NET classes - System.Text.Json
6 Mar 2017 by Michael Doleman
A simple DAL with an integrated, lightweight model for database seeding from a JSON source, using the code-first method in Entity Framework.
31 May 2016 by Hamid Mosalla
Dynamically building JSON tree for use In JavaScript components using C#
23 Nov 2016 by robert_chang
Learn how easy it is to write a console application to find the Congressional District of a U.S. address using free geocoding web services.
26 Jul 2018 by Ajcek84
Dynamic proxy for lazy deserialization of large JSON files
17 Mar 2024 by Andre Oosthuizen
As I am all about PHP, I found this interesting to play around with, be forewarned though that there are WAY more to the below code than what is given, you have to insert certain security measures, you need to know how to start a session to grab...
2 Dec 2015 by Richard Deeming
Assuming the JSON you're receiving always looks the same, use the DeserializeAnonymousType method[^]:var table = JsonConvert.DeserializeAnonymousType(file, new { Makes = default(DataTable) }).Makes;
5 Sep 2016 by Aless Alessio
Serialize concrete classes that have interface properties
16 Mar 2017 by Robert Bettinelli
Easy JSON Recursion in VB.NET with nested levels
5 Oct 2020 by Robert P. Howard
How to deserialize a JSON string that contains nested polymorphic objects
16 Mar 2024 by Maciej Los
We are not a "C# to PHP" translator. I'd suggest to read this: How to begin? | C# to PHP converter[^]
5 Jan 2014 by Rajesh_DotNet
Hi.., I can give you a simple example for deserializing it. Here is my simple sample code which would give you some idea about it.using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication4{ public class...
26 May 2014 by DamithSL
you can use http://json2csharp.com/[^] to generate the clases from the json. for example below is the result for your json.public class Language{ public int id { get; set; } public string name { get; set; }}public class Speak{ public int id { get; set; } public...
26 Sep 2014 by Member 7483521
Hi,In my REST Controller I have a HTTP/PUT handler method. The issue is that when I receive updates, I do not want to send everything over the wire if only one property has changed.The way I do it now is having the handler accept a dynamic parameter, which I then apply to my LINQ objects...
7 May 2015 by Sergey Alexandrovich Kryukov
This is nonsense. XML document, by definition, has one and only one root. If you remove the root, the next level of hierarchy can be one element of more than one. If there is only one element, removing root will give you valid XML (or at least well-formed). This is not the case in your example,...
7 May 2015 by Maciej Los
If you want to skip root element and get only child nodes, use this:var invoices = xdoc.Root.Elements();Now, you can "convert" it into json object.Note, that using your code you'll get something like this:{"ExtSerial":"KDI2015050501"},{"Date":"02/01/2015"},...but...
16 May 2016 by Maciej Los
I'd recommend to start here: How to: Serialize and Deserialize JSON Data[^]When you'll be able to get a Key property/member as a string, you can use XDocument class[^] for further xml proccessing.Sorry, the description of your issue is not much informative...
26 Dec 2016 by robert_chang
Learn how to connect to Dynamics CRM, customize and query Customer Address entity, geocode the address and update CRM data.
12 Feb 2017 by Afzaal Ahmad Zeeshan
One single reason: Because you are not doing it correctly. You are deserializing it to a "list of list of posts". And your JSON is a "document containing posts". I could write something as simple as, // Skip compile time type checking, first. dynamic deserialize_post =...
8 Mar 2017 by Karthik_Mahalingam
Create a Class with the required properties public class MyType { public string Name { get; set; } public string Owner { get; set; } }and access it as a list.public async Task UploadFile(List jsonarraydata ){
26 Jul 2017 by Graeme_Grant
If you are having problems with converting the raw JSON, then pass the raw JSON data to JSON Utils: Generate C#, VB.Net, SQL Table, Java and PHP from JSON[^] and it will generate the C# class files for you. A DataTable is a "Flat View" and your data is not flat, it has multiple layers. If you...
23 Nov 2018 by Luke Vosyka
What if your Json contains a datetime value like "2018-11-23T20:56:05.3117673Z" and you need it to be in a BsonDocument as a proper BsonDateTime value?
22 Apr 2019 by F-ES Sitecore
Your data has a property called "result" which is an array so you need a class that reflects that. Something like class MyData { [JsonProperty("result")] public List Result { get; set; } [JsonProperty("success")] public bool Success { get; set; }...
6 Jul 2021 by Richard Deeming
Your class structure doesn't match your JSON. Public Class Root Public Property status As Boolean Public Property message As String Public Property data As List(Of BouncesAndBlocks) End Class Public Class BouncesAndBlocks Public...
16 Mar 2024 by OriginalGriff
As Maciej has said, this is not a code conversion service: we are not here to translate code for you. Even if we did, what you would end up with would not be "good code" in the target language – they are based on very different frameworks, and...
22 Oct 2013 by Jocelyne El Khoury
i fixed it :i'm trying to deserialize the JSON string into a Dictionary which should represent an object, but my JSON string contains an array of two objects instead of a single object.So ishould use List(Of Dictionary(Of String, String)) instead of Dictionary(Of String, String):Sub...
26 May 2014 by Mehdi Gholam
areas is an object with a property countries which is an array of string and date so you should add public class arr { public String iso_3166_1; public DateTime release_date;}public class Areas{ public List countries;}// and your type is...
26 May 2014 by Nirav Prabtani
convert it into dataset like this and then you can easily get data from dataset.. :)How to Convert JSON String into Dataset using c#[^]
26 May 2014 by Murali0195
Hi...http://stackoverflow.co...
30 May 2014 by Raul Iloc
The faster data fetching is storing and accessing data from the database, in your case using SQL database will be faster then using any files (XML, JSON, etc), if your data amount is not only few records.
12 Jun 2014 by Sergey Alexandrovich Kryukov
Most likely, you are talking about Newtonsoft.JSON: http://json.codeplex.com[^].If so, just look at the title:CodePlex says:Json.NETJson.NET is a popular high-performance JSON framework for .NETIt is not supposed to be anything like COM. You can expect that you are dealing with a .NET...
31 Jul 2014 by Nirav Prabtani
Put your function testJson() in jQuery document.ready function $(document).ready(function(){ testJson();});or you can set that function onload of body
2 Aug 2014 by Afzaal Ahmad Zeeshan
The answer is simple, since you're handling this script on the onclick event it would always trigger that way. If you want it to happen as soon as the page loads you can try to add it to the body tag, like thisThis would execute the very time when you will run the page to load it....
27 Aug 2014 by shivani 2013
>Hi, I have one record in which i have field"CurrentDate" as 8/27/2014but when i serialize it using var invoiceDataSerializer = new JavaScriptSerializer(); var invoiceData= invoiceDataSerializer.Serialize(invoiceSerializedList);it is coming in "invoiceData" as...
26 Jan 2015 by E.F. Nijboer
It would be best to handle this server side as mentioned in the comments already. You could ass typeValue as a parameter to the method GetProviderReport so you can also reuse it for other typeValues. In the foreach you would need an if statement because the condition in the foreach would...
17 May 2015 by Sergey Alexandrovich Kryukov
Please see: https://sixgun.wordpress.com/2012/02/09/using-json-net-to-generate-jsonschema[^].You should understand that generating metadata from data can be ambiguous; it depends on how representative your data sample is.[EDIT]My last paragraph above suggests that this approach may...
16 Dec 2015 by Nathan Minier
That's because the JSON (de)serializer is looking for an array and is getting an object.You can solve this in one of two ways; the first (and easiest) is to change the type of ScoreData to more appropriately reflect the incoming data:[DataMember()] public object ScoreData;You...
25 Dec 2015 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
In this blog, I will tell you the trick to convert JSON string property to C# Object using Newtonsoft.
7 May 2016 by Richard Deeming
Converting this to a for loop seems simple enough:listcapac = [];var rooms = $('#tbl_Capacity tr').length - 1;for (var i = 0; i
10 Jun 2016 by Karthik_Mahalingam
Try this,underline codes are corrected$.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "http://localhost:4780/WebServiceRegistering.asmx/Registering", data: "{ 'Id': 8 }", ...
8 Dec 2016 by swapnilsonawane123
Below solution works if you iterating json on page itself. $(function () { var _Obj = { "delivery_codes": [{ "postal_code": { "district": "Bellary", "pin": 583217, "max_amount": 0.0, "pre_paid": "N", "cash": "N", "pickup": "N", "repl": "N", "cod": "N", "sort_code":...
7 Mar 2017 by Richard Deeming
The first problem is that you haven't initialized the list, so rootjson.ListSourcesFile returns null, and any attempt to index into the list throws a NullReferenceException.The second problem is that you haven't added anything to the list. When you try to retrieve the first item of an empty...
14 Mar 2017 by Graeme_Grant
vehicle-makes is not a valid object name but vehicle_makes is.
14 Mar 2017 by Bryian Tan
You can also wrap it in a bracket [], see below as an example.Object name with dash[^]var mytb = JsonConvert.DeserializeAnonymousType(JSONfile, new { vehiclemakes = default(DataTable) })["vehicle-makes"];
15 Mar 2017 by Graeme_Grant
The problem that you are having is that you have complex node names that don't directly translate to .Net variable names. So Dynamic object creation is failing. Examples of this are:vehicle-model\"track-pack\"-gauges3xlock-start-from-oem-remoteAll are invalid names .Net names but valid...
26 Jul 2017 by BillWoodruff
The error message is very clear: RootObject causes an error because 'RootObject is not a generic Type. You need to first get your JSON result (string), then use the Newtonsoft.Json.Converters.DataTableConverter class facilities to convert it to a DataTable [^]. It's important, if...
29 Nov 2017 by F-ES Sitecore
That's pretty complex JSON to interpret, and not particularly well designed in my opinion. I think it'll be hard to get something to convert that to XML automatically in a format that is going to look decent, you might need to do some of your own parsing of the data. This might get you started...
9 Jan 2018 by Karthik_Mahalingam
try dynamic _userin = JsonConvert.DeserializeObject(json); foreach (var item in _userin) { string name = item.Name; string time = item.Value.time; string type = item.Value.type; string bounceType = item.Value.bounceType; ...
13 Jan 2018 by Thomas Daniels
Your code is:debugOutput("Name: " + jPerson.Name); But your property definition is: public string name { get; set; } So that's name rather than Name: C# identifiers are case-sensitive.
18 Jan 2018 by Graeme_Grant
This article goes into detail on how to Deserialize JSON and the tools that you can use to help you: Working with JSON in C# & VB[^] Here is the code generated by JSON Utils: Generate C#, VB.Net, SQL Table, Java and PHP from JSON[^]: namespace WhitePagesTool {         public class BelongsTo...
29 Apr 2018 by Eric Lynch
You're biggest problems are with the AppointmentReasonList and ReasonCodeList classes. In your JSON document, these are represented as collections. However, since both classes simply implement IEnumerable{T}, there is no way the de-serializer can add elements to the collection. Consider...
21 May 2018 by Patrice T
const string selectQuery = "SELECT * FROM tbl_sales WHERE (row_inserted_on >= @dtp_last_updated) AND (last_edited_on >= @dtp_last_updated)"; $query .= "INSERT INTO tbl_sales(sale_item, sale_qty, row_inserted_on, last_edited_on, id) VALUES ('".$row["sale_item"]."', '".$row["sale_qty"]."',...
1 Sep 2018 by Graeme_Grant
I wrote an article to help answer questions commonly asked in here: Working with JSON in C# & VB[^] Your question is about serialization of class to raw JSON, something not covered in detail in the article, so I will answer here using Newtonsoft's Json.NET[^] library. To make sure that your...
20 Dec 2018 by Vincent Maverick Durano
I'd suggest you to create a concrete class for each object that you want to return as an output instead of relying on anonymous types. This way you could easily modify the object that you want to add/remove and it's easy to maintain it. For example you could create the following class: ...
20 Dec 2018 by Richard Deeming
string jsonsign1 = new JavaScriptSerializer().Serialize(new { data = new { amount = 100, currencyType = "MYR", expiry = new { type = "PERMANENT" }, isPreFillAmount = true, order = new { detail = "detail", title =...
13 Feb 2019 by OriginalGriff
Probably, your class names don't match. If I feed your JSON into a class generator (json2csharp - generate c# classes from json[^]) I get these: public class Testinfo { public int testid { get; set; } public string testshortdescription { get; set; } public...
11 Nov 2019 by OriginalGriff
First off, your classes don't entirely match the JSON: if you add the appropriate curly brackets to your data to make it "valid JSON" and run it through a class generator: json2csharp - generate c# classes from json[^] then you get a load of "__invalid_type__" classes generated which means that...
29 Mar 2020 by Afzaal Ahmad Zeeshan
You can read my article to understand how to work with JSON data in C#, From zero to hero in JSON with C#[^]. It gives you an overview of JSON data, Newtonsoft library for JSON handling and a bunch of other tips. Now as for the question and this...
19 May 2020 by Richard Deeming
The value you're trying to deserialize doesn't match the JSON you've shown. To deserialize that JSON, your classes need to look like: Public Class Root _ Public Property OdataContext As Uri ...
19 May 2020 by OriginalGriff
If I pass your code to a Class creator (such as JSON Utils: Generate C#, VB.Net, SQL Table, Java and PHP from JSON[^]) I dont; get such a limited class, as I'd expect: Public Class Value Public Property cotacaoVenda As Double End...
6 Jul 2020 by Richard Deeming
Change the shape of the data you're returning: [HttpPost] public JsonResult AddNewEvent(Event e) { try { using(EventsDBEntities db = new EventsDBEntities()) { if (db.Events.Any(x => x.Title == e.Title)) ...
4 Aug 2020 by Member 13668663
I am trying to create a JSON schema with the usage of Json.NET Schema. Anyway, my class has JsonConverter attribute, like in the example below: public class Building { [JsonConverter(typeof(BuildConverter))] public string Name { get; set; }...
18 Aug 2020 by OriginalGriff
This is not a technical support site for phones: start with the people you bought it from and / or the phone manufacturers.
22 May 2021 by Sandeep Mewara
You can use any online JSON to C# class converter for the same: // Usage // Root myDeserializedClass = JsonConvert.DeserializeObject(myJsonResponse); public class Location { public double lat { get; set; } public double lon {...
14 Feb 2022 by OriginalGriff
Start by defining classes that are compatible with the JSON data: Convert JSON to C# Classes Online - Json2CSharp Toolkit[^] will do that for you: public class RdfsClass { [JsonProperty("@id")] public string Id { get; set;...
28 Sep 2022 by Graeme_Grant
Here are the classes for that JSON data: ����public�class�Metadata ����{ ��������[JsonProperty("name")] ��������public�string�Name�{�get;�set;�} ��������[JsonProperty("latitude")] ��������public�double�Latitude�{�get;�set;�} ...
12 Aug 2013 by Member 10054218
how to parse JSON data?i have following data:{"Movies":[{"Movie":{"id":"102","name":"Bombay...
29 Aug 2013 by syna syna
$('#xxxxgrid').processTemplate...
27 Sep 2013 by IanMac91
I have the following JSON that is stored in a string.{"authenticationResultCode":"ValidCredentials","brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png","copyright":"Copyright © 2013 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and...
3 Oct 2013 by kingsa
Hi , Hi i have table in sqlserver i want to whole table in json format ,for that what data type have to used , can u guide or send snippets
3 Oct 2013 by ♥…ЯҠ…♥
Hi Suhelsa, I hope this link[^] would help you a bitRegards,RK
16 Oct 2013 by Jocelyne El Khoury
i'm trying to read a json string from an http post, i'm trying to test my code by filling the json string manually but my problem is that i'm not able to add the same node many times.... in other words if i put the following it works: Dim json As String = "{'name': 'jocelyne','mo':...
21 Oct 2013 by kingsa
Hi I want to create wcf service returns format in json , data get for service should gets using linq to sqlclasses can u guide me or send snippets
21 Oct 2013 by Ranjan.D
Here's some links.. These are pure basic articles. http://www.mikesknowledgebase.com/pages/Services/WebServices-Page1.htm[^]http://www.wikihow.com/Use-LINQ-to-SQL-in-C-Sharp[^]PS: Never mind you seem to forget Google.
21 Oct 2013 by kingsa
Hi , i want to below code into edmx or linq same thing using guide me or send snippets, the data should be return in json format ,for that i am using in wcf service public Employee[] GetAllEmployee() { List lstEmp = new List(); ...
22 Oct 2013 by Jocelyne El Khoury
i am receiving through http post the following string as json: Dim json As String = "[{" + """name"":""jocelyne" + """," + """mo"":""jocelyne" + """}" + ",{" + """name"":""eliane" + """," + """mo"":""12345678" + """}" + "]"i need to convert this json array to a datatable in vb.neti...
22 Oct 2013 by Nhilesh B
Hi,I am not sure, if you want to use C# but this is much simple with the DLL, I use ["Newtonsoft.Json.dll"] found at http://json.codeplex.com/[^].There are two methods available i.e Serialize and Deserialize data-table public static string Serialize(object value) { ...
22 Oct 2013 by Ranjan.D
Have a look into the below mentioned article to learn how to create a EF based solution.Using the Entity Framework 4.3 in .NET Development[^]
23 Oct 2013 by Jocelyne El Khoury
I have this function in ASP.NET to convert a DataTable to JSON string:Public Function GetJson(ByVal dt As DataTable) As String Dim serializer As System.Web.Script.Serialization.JavaScriptSerializer = New System.Web.Script.Serialization.JavaScriptSerializer() Dim rows As New List(Of...
8 Dec 2013 by Rambo_Raja
How can i bind the data returned by json object d to jquery grid ? I have tried using asp.net gridview but failed. I have seen some links of jquery grid but no source code is available in my aspx this is what i have done:function get(strcode) { $.ajax({ type: "POST", ...
8 Dec 2013 by sankarsan parida
http://www.aspsnippets.com/Articles/Bind-data-to-GridView-with-jQuery-or-JSON-in-ASPNet.aspx
8 Dec 2013 by JoCodes
There is a nice CP article which you can refer.Using JqGrid in ASP.NET[^]Hope this helps you...
19 Dec 2013 by Member 10336798
Hi, im trying to deserialize the following JSON String:http://docs.ninja.is/rest/device.html#device-get-devices[^]{ "result": 1, "error": null, "id": 0, "data": { "ASTEALTHYNODE01_0301_0_30": { "css_class": "sensor rf digital humidity", ...
20 Dec 2013 by Sunny_Kumar_
You go ahead and use Json.Net to deserialize this JSON, it's deserialized very well.check it here:[^]is not working well... check out this one:http://json.parser.online.fr/[^]HTH!
12 Feb 2014 by rishiraj malvi
Hello Everyone, I have classes in my application generated by Json :-public class Answer { public string answerId { get; set; } public string answer { get; set; } }public class Question{ public string questionId { get; set; } public string questionTitle { get; set; } ...
12 Feb 2014 by hitech_s
Use observable collections of questions and bind to the ui.after finishing all the questions user will hit submit button there you just read the observable collection it contains the answers selected by the user.
14 Feb 2014 by tonyjoseph456
I'm trying to send a json object from my android activity to my asp.net web service, by the following code.//This is Category.javaJSONObject json=new JSONObject();try{ CallSoap cs=new CallSoap(); String name="Ramu"; String username="ramu@gmail.com"; String...
14 Feb 2014 by Ravi Bhavnani
See this[^] article for instructions on how to post a JSON request to a webservice from Android.I recommend using ASP .NET MVC to implement your webservice.  The default model binder will populate your model using the JSON properties sent by your Android (or any other type of) client.  See...
16 Feb 2014 by Member 10476757
http://www.jqwidgets.com/binding-jquery-grid-to-json-data/[^]
16 Feb 2014 by Dharmit vyas
I thnk in this type of scenarios you can use KENDO UI , very flexible to use.http://demos.telerik.com/kendo-ui/web/grid/index.html[^]
17 Feb 2014 by rishiraj malvi
it get all the question & option on next button by declaring List question and get all values from obj of main.
24 Feb 2014 by Aswathi Narayan
Hai,Am using this code for Inserting Data..I need to pass dat as object array.. How can I write code for this??????var dat = "{FeeNameId:'"+FeeNameId+"',FeeName:'" + FeeName + "',FeeType:'"+FeeType+"'}"; var url="../Services/FeesService.asmx/InsertFeeName" ...
11 Mar 2019 by Scimiazzurro
I'm making an application with C# and Mono framework (to make it compatible with Linux).In this app I'm using also the Json.NET library, but it doesn't seem to work with Mono because every time I try to start the application I get this error:Missing method .ctor in assembly...
20 Mar 2014 by Vladimir Svyatski
Here you can find some info about this class. As I can see, the class was introduced in the .Net 3.5, so this stuff may not be supported by Mono. Just for you to know: not every feature of .NET is supported by Mono. Json.NET is also may not be supported by Mono properly. So I'd suggest to check...
2 Apr 2014 by Appdev(Icode)
HiI'm creating a webservice which should get data from database(sql server) and return it.Every thing working fine.But what i need is i need to display the data with the format which i need.Here is my code:using System;using System.Collections.Generic;using System.Linq;using...
2 Apr 2014 by Sanjay K. Gupta
Use below helper codeprivate static Dictionary> DatatableToDictionary(DataTable dt) { var cols = dt.Columns.Cast(); return dt.Rows.Cast() .ToDictionary(r =>...
3 Apr 2014 by Appdev(Icode)
HiI made few changes in my code now it works perfectHere is my code:public string GetEmployees() { System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); SqlConnection con =...
2 May 2014 by vaeaze
In the view I want to get the json data like this: [{"name":"NewWork", "data":[{"\/Date(1398787200000)\/",196}, {"\/Date(1398009600000)\/",62}, {"\/Date(1397836800000)\/",65}] }, {"name":"BeiJing", ...
13 May 2014 by ramjiricky
Hi i have my master page with popup in popup i have submit button, once i click the submit button in popup i need to pass the data to db it done successfully but at the same time i need to pass some textbox value to content page and bind that in label while click submit those data need to be ...