首页 > 代码库 > JOSN反串行化

JOSN反串行化

JOSN编码的数据可以使用eval函数生产操作的类型。

<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title>    <script type="text/javascript">        var JSONstring = {+            "artist" : "Phish",+            "title" : "A Picture of Nectar",+            "releaseYear" : 1992,+            "tracks" :  [+             "Llama",+             "Eliza",+             "Cavern",+             "Poor Heart",+             "Stash",+             "Manteca",+             "Guelah Papyrus",+             "Magilla",+             "The Landlady",+             "Glide",+             "Tweezer",+             "The Mango Song",+             "Chalk Dust Torture",+             "Faht",+             "Catapult",+             "Tweezer Reprise",+            ]+        };        function pageLoad() {            var album = eval("(" + JSONstring + ")");            var innerHTML = "artist = " + album.artist + "<br />" +                "title = " + album.title + "<br />" +                "releaseYear = " + album.releaseYear;            $get(placeholder).innerHTML = innerHTML;            var tracks = "";            for (var i = 0; i < album.tracks.length; i++) {                tracks += "tracks #" + i + " = " + album.tracks[i] + "<br />";            }            $get(placeholder2).innerHTML = tracks;        }    </script></head><body>    <form id="form1" runat="server">    <div>        <asp:ScriptManager ID="ScriptManager1" runat="server">        </asp:ScriptManager>        <div id="placeholder"></div>        <div id="placeholder2"></div>    </div>    </form></body></html>

 

JOSN反串行化