Mark Tabor

Mark Tabor

  • 562
  • 2k
  • 452.7k

My json is not correct format i have tried indented and none both belo

Sep 13 2022 7:17 PM

My return json is bad formated like below 

[\r\n  {\r\n    \"Result\": null,\r\n    \"Description\": null,\r\n 

how to fix it

public JsonResult Getcust(string Country, string Username)
{
    MYCUST response = new MYCUST();

    try
    {
        using (DB_Entities db = new DB_Entities())
        {
            List findcust = (from g in db.Customers
                            where g.COUNTRY == "USA"
                            select new MYCUST
                            {
                                state = g.state,
                                City = g.city,
                                
                                Village = g.VILLAGE,
                                sid = (int)g.SID,
                                cid = (int)g.CID,
                               
                                vid = (int)g.VID,
                            }).ToList();
            response.Result = "OK";
            response.myPotentialCust = findcust;
            string jsonEmp2 = JsonConvert.SerializeObject(findSiteLocations, Newtonsoft.Json.Formatting.Indented);
           return Json(JsonEmp2,JsonRequestBehavior.AllowGet);

        }
    }
    catch (Exception ex)
    {
        response.Result = "FailedGeoLocations";
        
        return Json(response, JsonRequestBehavior.AllowGet);
    }
}

 


Answers (1)