Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read data from json on C#

Tags:

I have the following json Object that I pass to my c# server

[
    {
        "ID": 1,
        "FirstName": "Jay",
        "LastName": "Smith"
    },
    {
        "ID": 2,
        "FirstName": "Rich",
        "LastName": "Son"
    },
    {
        "ID": 3,
        "FirstName": "Emmy",
        "LastName": "Wat"
    }
]

I create a Class like this

public class Person
{
    public int ID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

}

When I do this

public static string addRecord(string details)
{
    Person tempRecord = JsonConvert.DeserializeObject<Person>(details);
    string tempFN = tempRecord.FirstName;
    return tempFN;
}

I can't get the actual result.

What am I doing Wrong? Do I have to make another List in my Person class? Any help?

UPDATE - my record is from Grid and this is how I send it to my server

    var jsonD = Ext.encode(Ext.pluck(this.myGridStore.data.items, 'data'));
    Ext.Ajax.request({
        scope: this,
        method: 'POST',
        url: 'myApp/AddRecord',
        headers: { 'Content-Type': 'application/json' },
        dataType: 'json',
        jsonData: jsonD,
        success: function (response) {
        },
        failure: function (response) {
        }
    });