0

I want to convert json to javascript array but its not working,

I tried the follwoing.

var arr = $.map(RatingGrade,function(value){ return value; });


var arr =  Object.keys(RatingGrade).map(function(k) { return RatingGrade[k] });//not working on ie8
$.parse()
[{
        "RGCode": 61,
        "RGCode1": 61,
        "ScoreMin": -1,
        "ScoreMax": -1,
        "GradeNo": "1+",
        "GradeName": "Excellent",
        "GradeDescription": "Excellent",
        "createdby": 23,
        "createdon": "/Date(1413970769020)/",
        "updatedby": 23,
        "updatedon": "/Date(1438628400000)/",
        "status": "A",
        "ScoreCardID": 1,
        "PDLowerBound": 0,
        "PDUpperBound": 0.03,
        "MidPoint": 0.02,
        "MaxPDMinPDDifference": 0.03,
        "AveragePD": 0
    }

     ]

how can i do this?also stringfy also but not working

McVenco
  • 1,011
  • 1
  • 17
  • 30
Brave Man
  • 315
  • 1
  • 2
  • 10
  • you can try `$.parseJSON(yourJSONString)'` this will give you a JSON object. – Sushil Aug 04 '15 at 22:31
  • @Sushil not working return null – Brave Man Aug 04 '15 at 22:32
  • 1
    that's already a javascript array...what exactly are you trying to do? – charlietfl Aug 04 '15 at 22:33
  • @Amit not working as you provide link,why not converting? – Brave Man Aug 04 '15 at 22:35
  • 1
    Are you trying to convert an object into an array??? Show your exact INPUT and exact expected OUTPUT (Without all that messy code) – Amit Aug 04 '15 at 22:35
  • try this `var myJSONString = '[{"RGCode":61,"RGCode1":61,"ScoreMin":-1,"ScoreMax":-1,"GradeNo":"1+","GradeName":"Excellent","GradeDescription":"Excellent","createdby":23,"createdon":"/Date(1413970769020)/","updatedby":23,"updatedon":"/Date(1438628400000)/","status":"A","ScoreCardID":1,"PDLowerBound":0,"PDUpperBound":0.03,"MidPoint":0.02,"MaxPDMinPDDifference":0.03,"AveragePD":0} ]'; var jsonObject = $.parseJSON(myJSONString);` – Sushil Aug 04 '15 at 23:20

2 Answers2

0

What about?

JSON.parse('[{"RGCode": 61,"RGCode1": 61,"ScoreMin": -1,"ScoreMax": -1,"GradeNo": "1+","GradeName": "Excellent","GradeDescription": "Excellent","createdby": 23,"createdon": "/Date(1413970769020)/","updatedby": 23,"updatedon": "/Date(1438628400000)/","status": "A","ScoreCardID": 1,"PDLowerBound": 0,"PDUpperBound": 0.03,"MidPoint": 0.02, "MaxPDMinPDDifference": 0.03,"AveragePD": 0}]').forEach(function(item){ 
    console.log(item); 
});

This is an array. You just have to parse it.

biancamihai
  • 961
  • 6
  • 14
0

Looks like map should do the job. Check the code and leave a comment if that does not work for you!

var data = {
  "RGCode": 61,
  "RGCode1": 61,
  "ScoreMin": -1,
  "ScoreMax": -1,
  "GradeNo": "1+",
  "GradeName": "Excellent",
  "GradeDescription": "Excellent",
  "createdby": 23,
  "createdon": "/Date(1413970769020)/",
  "updatedby": 23,
  "updatedon": "/Date(1438628400000)/",
  "status": "A",
  "ScoreCardID": 1,
  "PDLowerBound": 0,
  "PDUpperBound": 0.03,
  "MidPoint": 0.02,
  "MaxPDMinPDDifference": 0.03,
  "AveragePD": 0
}
var arr = Object.keys(data).map(function(T) {
  return data[T]
});
console.log(arr);