0

i want to get 5 top ten records of Temperature column and want to convert into json data. i tried like this but not getting desired values

{"success":true,"sensorsdata":{"WaterTemperature":"33.33"}}

  using (smartpondEntities DB = new smartpondEntities())
                {
                    var parkingSlot = DB.ParkingSlots.OrderByDescending(x => x.CurrentTime).Select(x => x.WaterTemperature).Take(5);

                    return Json(new { success = true, sensorsdata = new { WaterTemperature = "33.33" } }, JsonRequestBehavior.AllowGet);
                }
krishna mohan
  • 15
  • 1
  • 4
  • The error details would be helpful – H77 Jun 27 '16 at 08:33
  • Look at the following post - might help: [Turn C# object into a JSON string in .NET 4](http://stackoverflow.com/questions/6201529/turn-c-sharp-object-into-a-json-string-in-net-4) – Gilad Green Jun 27 '16 at 08:36
  • i have updated my question.kindly help me out how to get 5 values form table – krishna mohan Jun 27 '16 at 08:42
  • Why aren't you using the values you read into parkingSlot in your return statement? – H77 Jun 27 '16 at 08:49
  • return Json(new { success = true, sensorsdata = new { WaterTemperature = parkingSlot. } }, JsonRequestBehavior.AllowGet); after parkingslot im not getting watertempreture property – krishna mohan Jun 27 '16 at 09:05
  • I would assume you need to do something like this: double[] tempratures = parkingSlot.ToArray(); return Json(new { success = true, sensorsdata = new { WaterTemperature = tempratures } }, JsonRequestBehavior.AllowGet); However i do not know what Json() does, but you can put a breakpoint after you project your data into an array (or list, if you wish), to check what data you downloaded. – Snellface Jun 27 '16 at 11:14

0 Answers0