Note that there are some explanatory texts on larger screens.

plurals
  1. PORead JSON in C#
    text
    copied!<p>I am creating a web service to take the input in <strong>JSON</strong>. Please see the code below:</p> <p><strong>Registration.asmx</strong></p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Script.Serialization; using System.IO; using AnkTech.IsItFair.WebService.Providers; using System.Json; using System.Runtime.Serialization.Json; using Newtonsoft.Json.Serialization; using Newtonsoft.Json; namespace WebService { /// &lt;summary&gt; /// Summary description for Registration /// &lt;/summary&gt; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public class Registration : System.Web.Services.WebService { [WebMethod] public int SaveUser() { string json = @"{""data"":[{""Id"":""518523721"",""Name"":""ftyft""}]}"; Users tempRecord = JsonConvert.DeserializeObject&lt;Users&gt;(json); return 1; } } } </code></pre> <p><strong>Users.cs</strong></p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Json; using System.Runtime.Serialization.Json; using Newtonsoft.Json.Serialization; using Newtonsoft.Json; namespace WebService.Providers { [JsonObject(MemberSerialization.OptIn)] public class Users { [JsonProperty(PropertyName = "Id")] public string Id { get; set; } [JsonProperty(PropertyName = "Name")] public string Name { get; set; } } } </code></pre> <p>When I check my object <strong>tempRecord</strong>, I found the null values of my both properties i.e.<strong>Id</strong> and <strong>Name</strong>. What I am doing wrong. Please help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload