JSON对象、字符串互转,JS数组、字符串互转

下载json2.js

<script language="javascript" type="text/javascript" src="https://raw.githubusercontent.com/douglascrockford/JSON-js/master/json2.js"></script>
<script>
		//JSON对象转字符串
        function jsonObjToStr(data){
            return JSON.stringify(data);
        }
		//JSON字符串转对象
        function jsonStrToObj(data){
            return JSON.parse(data);
        }
		//JS数组转字符串
        function arrToStr(data){
            return data.join("@@@");
        }
		//JS字符串转数组
        function strToArr(data){
            return data.split("@@@");
        }
</script>

Related posts:

Leave a Reply

Your email address will not be published.