Home > DeveloperSection > Forums > How to Parsing A JSON File With C# mvc.
Ankit Singh

Total Post:341

Points:2389
Posted on    January-24-2016 10:19 PM

 ASP.NET MVC ASP.Net  ASP.NET MVC  Mvc 
Ratings:


 1 Reply(s)
 355  View(s)
Rate this:
I want to use Parsing A JSON File With C# Mvc. How to do this please help me.


aditya kumar Patel

Total Post:242

Points:1722
Posted on    January-24-2016 10:23 PM

 

 @model IEnumerable<ForumMVC.Models.Customer>  
    <!DOCTYPE html> 
    <html> 
        <head> 
            <meta name="viewport" content="width=device-width" /> 
            <title>Index</title> 
        </head> 
        <body> 
            <p></p> 
            <table class="table"> 
                <tr> 
                    <th> 
 
                        @Html.DisplayNameFor(model => model.FirstName) 
 
                    </th> 
                    <th> 
 
                        @Html.DisplayNameFor(model => model.LastName) 
 
                    </th> 
                    <th> 
 
                        @Html.DisplayNameFor(model => model.EmailId) 
 
                    </th> 
                    <th></th> 
                </tr> 
 
                    @foreach (var item in Model) { 
 
 
                    <tr> 
                        <td> 
 
                            @Html.DisplayFor(modelItem => item.FirstName) 
 
                        </td> 
                        <td> 
 
                            @Html.DisplayFor(modelItem => item.LastName) 
 
                        </td> 
                        <td> 
 
                            @Html.DisplayFor(modelItem => item.EmailId) 
 
                        </td> 
                    </tr> 
                } 
 
            </table> 
        </body> 
    </html> 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;

namespace ForumMVC.Models
{
    public class Customer
    {
        public int CustomerId
        {
            get;
            set;
        }
        public string FirstName
        {
            get;
            set;
        }
        public string LastName
        {
            get;
            set;
        }
        public string EmailId
        {
            get;
            set;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ForumMVC;
using System.Data.Entity;
using ForumMVC.Models;
using System.Web.Script.Serialization;
namespace ForumMVC.Controllers
{
    public class HomeController : Controller
    {
       
        public ActionResult Index()
        {           
            string file = Server.MapPath("~/App_Data/Customer.json");       
            string Json = System.IO.File.ReadAllText(file);
            JavaScriptSerializer ser = new JavaScriptSerializer();
            var  list = ser.Deserialize<List<Customer>>(Json);
            return View(list);            
        }

    }
}



    "CustomerId": 1, 
    "FirstName": "sudhesh", 
    "LastName": "Patel", 
    "EmailId": "sudhesh@gmail.com
}, 

    "CustomerId": 1, 
    "FirstName": "suresh", 
    "LastName": "Patel", 
    "EmailId": "suresh@gmail.com
}, 

    "CustomerId": 1, 
    "FirstName": "Shiv Shingh", 
    "LastName": "Patel", 
    "EmailId": "shiv@gmail.com
}, 

    "CustomerId": 1, 
    "FirstName": "manoj", 
    "LastName": "Patel", 
    "EmailId": "manoj@gmail.com
}, 

    "CustomerId": 1, 
    "FirstName": "mayank", 
    "LastName": "Patel", 
    "EmailId": "manoj@gmail.com
}, 

    "CustomerId": 1, 
    "FirstName": "Mohit", 
    "LastName": "Patel", 
    "EmailId": "mohit@yahoo.com
}]


Don't want to miss updates? Please click the below button!

Follow MindStick