Parsing malformed JSON in JavaScript

前端 未结 5 607
别跟我提以往
别跟我提以往 2020-12-07 04:38

Thanks for looking!

BACKGROUND

I am writing some front-end code that consumes a JSON service which is returning malformed JSON. Specifically, the keys are n

5条回答
  •  执笔经年
    2020-12-07 05:24

    How about?

    function fixJson(json) {
        var tempString, tempJson, output;
    
        tempString = JSON.stringify(json);
        tempJson = JSON.parse(tempString);
        output = JSON.stringify(tempJson);
    
        return output;
    }
    

提交回复
热议问题