Convert Javascript Object (incl. functions) to String

后端 未结 10 1033
你的背包
你的背包 2020-12-29 21:35

Hey, Im trying to convert specific javascript objects to a String. So far I\'m working with json2.js. As soon as my Object contain functions, those functions are stripped. I

10条回答
  •  时光取名叫无心
    2020-12-29 22:06

    So I was just testing your script on one of my project, and there's a problem with Object keys that contain special characters (like / or -).

    You should consider wrapping theses keys with quotes.

    return `"${entry[0]}" : ${anyToString(entry[1])}`;
    

提交回复
热议问题