Doc/SerializingCollections.html
(开头部分) 8KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<html>
<head>
<title>Serializing Collections</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<link href="custom.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="control">
<span class="productTitle">Json.NET - Quick Starts & API Documentation</span><br />
<span class="topicTitle">Serializing Collections</span></div>
<div id="content">
<span style="color: DarkGray"> </span>
<p>The <a href="./html/T_Newtonsoft_Json_JsonSerializer.htm">JsonSerializer</a> has
great support for serializing and deserializing collections of objects.</p>
<h3>Serializing</h3>
<p>To serialize a collection - a generic list, array, dictionary, or your own custom collection - simply call the serializer with the object you want to get JSON for.
Json.NET will serialize the collection and all of the values it contains.</p>
<div class="overflowpanel"> <div class="code">
<div style="font-family: Courier New; font-size: 10pt; color: black;">
<pre style="margin: 0px;"><span style="color: #2b91af;">Product</span> p1 = <span style="color: blue;">new</span> <span style="color: #2b91af;">Product</span></pre>
<pre style="margin: 0px;"> {</pre>
<pre style="margin: 0px;"> Name = <span style="color: #a31515;">"Product 1"</span>,</pre>
<pre style="margin: 0px;"> Price = 99.95m,</pre>
<pre style="margin: 0px;"> ExpiryDate = <span style="color: blue;">new</span> <span style="color: #2b91af;">DateTime</span>(2000, 12, 29, 0, 0, 0, <span style="color: #2b91af;">DateTimeKind</span>.Utc),</pre>
<pre style="margin: 0px;"> };</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">Product</span> p2 = <span style="color: blue;">new</span> <span style="color: #2b91af;">Product</span></pre>
<pre style="margin: 0px;">{</pre>
<pre style="margin: 0px;"> Name = <span style="color: #a31515;">"Product 2"</span>,</pre>
<pre style="margin: 0px;"> Price = 12.50m,</pre>
<pre style="margin: 0px;"> ExpiryDate = <span style="color: blue;">new</span> <span style="color: #2b91af;">DateTime</span>(2009, 7, 31, 0, 0, 0, <span style="color: #2b91af;">DateTimeKind</span>.Utc),</pre>
<pre style="margin: 0px;">};</pre>
<pre style="margin: 0px;"> </pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">List</span><<span style="color: #2b91af;">Product</span>> products = <span style="color: blue;">new</span> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">Product</span>>();</pre>
<pre style="margin: 0px;">products.Add(p1);</pre>
<pre style="margin: 0px;">products.Add(p2);</pre>
<pre style="margin: 0px;"> </pre>
<pre style="margin: 0px;"><span style="color: blue;">string</span> json = <span style="color: #2b91af;">JsonConvert</span>.SerializeObject(products, <span style="color: #2b91af;">Formatting</span>.Indented);</pre>
<pre style="margin: 0px;"><span style="color: green;">//[</span></pre>
<pre style="margin: 0px;"><span style="color: green;">// {</span></pre>
<pre style="margin: 0px;"><span style="color: green;">// "Name": "Product 1",</span></pre>
<pre style="margin: 0px;"><span style="color: green;">// "ExpiryDate": "\/Date(978048000000)\/",</span></pre>
<pre style="margin: 0px;"><span style="color: green;">// "Price": 99.95,</span></pre>
<pre style="margin: 0px;"><span style="color: green;">// "Sizes": null</span></pre>
<pre style="margin: 0px;"><span style="color: green;">// },</span></pre>
<pre style="margin: 0px;"><span style="color: green;">// {</span></pre>
<pre style="margin: 0px;"><span style="color: green;">// "Name": "Product 2",</span></pre>
<pre style="margin: 0px;"><span style="color: green;">// "ExpiryDate": "\/Date(1248998400000)\/",</span></pre>
<pre style="margin: 0px;"><span style="color: green;">// "Price": 12.50,</span></pre>
<pre style="margin: 0px;"><span style="color: green;">// "Sizes": null</span></pre>
<pre style="margin: 0px;"><span style="color: green;">// }</span></pre>
<pre style="margin: 0px;"><span style="color: green;">//]</span></pre>
后面还有 68 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
