-1

I have following json but I am not able to get results from the json

{"records":[{"Id":"EAAAAMQFNOLb3sYKmS2SByuEngKnNLcaGuDKpHIn1yo8Y-WC","PlateNo":"B108","ChassisNo":"8101108","AxleLoaded":null,"AxleSpacing":1,"ChangeInDimension":null,"FrontAxleLoadWeight":null,"RearSingleAxleLoadWeight":null,"NoSingleAxles":1,"NoTandomAxles":1,"NoMultiAxles":1,"NoTyresPerAxles":11,"MaxAxleLoadedLoad":1,"TyreLoadedLoad":1,"TyreWidth":1,"IsTrailer":true,"Cost":30,"CreatedOn":"\/Date(1549892412737)\/","CreatedById":"EAAAAMQFNOLb3sYKmS2SByuEngK94K-Aro6CPgaTtLl1wTsw","TirePressure":1,"LoadWeight":null,"UnloadedWeight":1,"Length":1,"Width":1,"Height":1,"LoadHeight":0,"RearTripleAxleLoaded":null,"LoadWidth":null}],"total":1}

I used following jquery code but it is showing undefined.I also tried with $.parseJSON, but not working I have assigned previous json to a varaible.

                   var mapdata = newVal;
                    alert(newVal);
                    $.each(mapdata, function (index, mapinfo) {

                        console.log(mapinfo.PlateNo);
                        alert(mapinfo.PlateNo);
                    });
p7adams
  • 622
  • 1
  • 9
  • 24
atc
  • 621
  • 8
  • 31

1 Answers1

0

Almost there missing index records since you have that format

var data = {
  "records": [{
    "Id": "EAAAAMQFNOLb3sYKmS2SByuEngKnNLcaGuDKpHIn1yo8Y-WC",
    "PlateNo": "B108",
    "ChassisNo": "8101108",
    "AxleLoaded": null,
    "AxleSpacing": 1,
    "ChangeInDimension": null,
    "FrontAxleLoadWeight": null,
    "RearSingleAxleLoadWeight": null,
    "NoSingleAxles": 1,
    "NoTandomAxles": 1,
    "NoMultiAxles": 1,
    "NoTyresPerAxles": 11,
    "MaxAxleLoadedLoad": 1,
    "TyreLoadedLoad": 1,
    "TyreWidth": 1,
    "IsTrailer": true,
    "Cost": 30,
    "CreatedOn": "\\/Date(1549892412737)\\/",
    "CreatedById": "EAAAAMQFNOLb3sYKmS2SByuEngK94K-Aro6CPgaTtLl1wTsw",
    "TirePressure": 1,
    "LoadWeight": null,
    "UnloadedWeight": 1,
    "Length": 1,
    "Width": 1,
    "Height": 1,
    "LoadHeight": 0,
    "RearTripleAxleLoaded": null,
    "LoadWidth": null
  }],
  "total": 1
}

$.each(data.records, function(index, mapinfo) {

  console.log(mapinfo.PlateNo);
  alert(mapinfo.PlateNo);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
guradio
  • 15,524
  • 4
  • 36
  • 57
  • Actually I am getting data from this jquery code. I copied the output. var data= $('#grid').load('/en/SpecialPermits/GetTrailer' + "?" + new Date().getTime()); – atc Feb 13 '19 at 08:28