Doc/LINQtoJSON.html

(开头部分) 21KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<html>
  
  <head>
    <title>LINQ to JSON</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">LINQ to JSON</span></div>

    <div id="content">
      <span style="color: DarkGray"> </span>
    
	<p>LINQ to JSON is a programming API for working with JSON objects. The API has been designed with LINQ in mind to enable to quick querying and creation of JSON objects. LINQ to JSON sits under the <a href="./html/N_Newtonsoft_Json_Linq.htm">Newtonsoft.Json.Linq</a> namespace.</p>

<h3>Creating JSON</h3>
<p>There are a number of different options when it comes to creating JSON using LINQ to JSON. The first to create objects imperatively. You have total control but it is more verbose than other options.</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;">JArray</span> array = <span style="color: blue;">new</span> <span style="color: #2b91af;">JArray</span>();</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">JValue</span> text = <span style="color: blue;">new</span> <span style="color: #2b91af;">JValue</span>(<span style="color: #a31515;">"Manual text"</span>);</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">JValue</span> date = <span style="color: blue;">new</span> <span style="color: #2b91af;">JValue</span>(<span style="color: blue;">new</span> <span style="color: #2b91af;">DateTime</span>(2000, 5, 23));</pre>
<pre style="margin: 0px;">&nbsp;</pre>
<pre style="margin: 0px;">array.Add(text);</pre>
<pre style="margin: 0px;">array.Add(date);</pre>
<pre style="margin: 0px;">&nbsp;</pre>
<pre style="margin: 0px;"><span style="color: blue;">string</span> json = array.ToString();</pre>
<pre style="margin: 0px;"><span style="color: green;">// [</span></pre>
<pre style="margin: 0px;"><span style="color: green;">//&nbsp;  "Manual text",</span></pre>
<pre style="margin: 0px;"><span style="color: green;">//&nbsp;  "\/Date(958996800000+1200)\/"</span></pre>
<pre style="margin: 0px;"><span style="color: green;">// ]</span></pre>
</div>

</div></div>

<p>Another option is to create JSON objects declaratively.</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;">List</span>&lt;<span style="color: #2b91af;">Post</span>&gt; posts = GetPosts();</pre>
<pre style="margin: 0px;">&nbsp;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">JObject</span> rss =</pre>
<pre style="margin: 0px;">&nbsp; <span style="color: blue;">new</span> <span style="color: #2b91af;">JObject</span>(</pre>
<pre style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">new</span> <span style="color: #2b91af;">JProperty</span>(<span style="color: #a31515;">"channel"</span>,</pre>
<pre style="margin: 0px;">&nbsp; &nbsp; &nbsp; <span style="color: blue;">new</span> <span style="color: #2b91af;">JObject</span>(</pre>
<pre style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">new</span> <span style="color: #2b91af;">JProperty</span>(<span style="color: #a31515;">"title"</span>, <span style="color: #a31515;">"James Newton-King"</span>),</pre>
<pre style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">new</span> <span style="color: #2b91af;">JProperty</span>(<span style="color: #a31515;">"link"</span>, <span style="color: #a31515;">"http://james.newtonking.com"</span>),</pre>
<pre style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">new</span> <span style="color: #2b91af;">JProperty</span>(<span style="color: #a31515;">"description"</span>, <span style="color: #a31515;">"James Newton-King's blog."</span>),</pre>
<pre style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">new</span> <span style="color: #2b91af;">JProperty</span>(<span style="color: #a31515;">"item"</span>,</pre>
<pre style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">new</span> <span style="color: #2b91af;">JArray</span>(</pre>
<pre style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">from</span> p <span style="color: blue;">in</span> posts</pre>
<pre style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">orderby</span> p.Title</pre>
后面还有 194 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。