自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

詳細(xì)闡述JSON 序列化的進(jìn)行轉(zhuǎn)換介紹

開發(fā) 前端
如果想要嘗試 Atom 到 JSON 的轉(zhuǎn)換,請(qǐng)?jiān)L問 Abdera wiki,獲取關(guān)于如何下載最新開發(fā)映像的信息,認(rèn)為JSON 序列化只會(huì)使我們的工作更簡(jiǎn)單和更輕松。

將數(shù)據(jù)從一種格式轉(zhuǎn)換成另一種格式總是一個(gè)很困難的任務(wù)。將 Atom 這樣豐富和強(qiáng)大的數(shù)據(jù)格式序列化為 JSON 這類簡(jiǎn)單的基本格式,一定會(huì)面臨許多問題,本文描述的技術(shù)只是其中的一種。

忽略所有擴(kuò)展,而且不要將它們包含在 JSON 序列化中 序列化已知擴(kuò)展,忽略其他所有擴(kuò)展 序列化所有擴(kuò)展 第一種選擇顯然是最簡(jiǎn)單的選擇,但是限制了 JSON 表示的整體效用(并不一定是件壞事)。第二種選擇允許對(duì)已知擴(kuò)展的 JSON 序列化進(jìn)行優(yōu)化和簡(jiǎn)化。#t#

將 Atom 序列化為 JSON 需要考慮的最后一個(gè)問題是,如何處理擴(kuò)展。有 3 種可能的選擇:但是仍然限制了序列化的效用。第三種選擇顯著增加了序列化的總體復(fù)雜性,但是能夠確保原始 Atom 文檔的所有信息都能夠通過(guò) JSON 表示出來(lái)。

首先討論如何優(yōu)化已知擴(kuò)展的輸出。Atom Threading Extension (RFC 4685) 提供了一種方法,可以表示某個(gè)條目是另一個(gè)條目的響應(yīng)。主題擴(kuò)展規(guī)范明確指定了 in-reply-to 元素的屬性和含義,并表示多個(gè) in-reply-to 元素可以出現(xiàn)在同一個(gè)條目中。了解了這一點(diǎn),就可以對(duì) in-reply-to 元素的 JSON 表示進(jìn)行優(yōu)化,如清單 26 和 27 所示。

  1. <entry>  ...  <thr:in-reply-to ref="tag:example.org,2007:/foo/entries/2" />
  2.   <thr:in-reply-to ref="tag:example.org,2007:/foo/entries/3" />  ...</entry> 

文檔轉(zhuǎn)換

現(xiàn)在,可以獲取任何 Atom 文檔并將其轉(zhuǎn)換為有用的JSON 序列化。清單 30 和 31 提供了轉(zhuǎn)換過(guò)程的完整演示。原始 Atom 文檔包含相對(duì) IRI、語(yǔ)言上下文、擴(kuò)展、多種文本和內(nèi)容類型等。使用從 Internet 上獲得的任何 XML 和 JSON 轉(zhuǎn)換器運(yùn)行此文檔,產(chǎn)生的序列化都不可避免地遇到數(shù)據(jù)丟失和/或可用性問題。

  1. <?xml version="1.0" encoding="utf-8" ?> <a:feed xmlns:a="http://www.w3.org/2005/Atom"    
  2.      xmlns:thr="http://purl.org/syndication/thread/1.0"      
  3.    xmlns="http://www.w3.org/1999/xhtml"      
  4.    xmlns:foo="http://example.org/unknown-markup"       
  5.   xml:lang="en-US"         xml:base="http://example.org/foo"     
  6.     dir="ltr">     <a:id>tag:example.org,2007:/foo</a:id>  
  7.  <a:title>Example Feed</a:title>   <a:subtitle type="html"><![CDATA[<p>This is an example feed</p>]]></a:subtitle> 
  8.   <a:rights type="xhtml">    <div>      <p>Copyright © James M Snell</p>  
  9.   </div>  </a:rights>   <a:author xmlns="http://www.w3.org/2005/Atom">    
  10.  <name>James M Snell</name>     <email>jasnell@example.org</email>    
  11.  <uri>/~jasnell</uri>   </a:author>   <a:updated>2007-10-14T12:12:12Z</a:updated>  
  12.  <a:link rel="self" href="" />   <a:link href="/blog" />   <a:link rel="alternate" 
  13. type="application/json" href="/blog;json" />     <a:entry xml:base="entries/1">     
  14. <a:id>tag:example.org,2007:/foo/entries/1</a:id>     <a:title type="text">Entry Number One</a:title>  
  15.    <a:summary type="xhtml">       <div>         <p>This is the first entry. You can read it <a href="">here</a></p>  
  16.      </div>     </a:summary>     <a:rights type="html">      <p>Copyright &copy; James M Snell</p>    </a:rights>  
  17.    <a:updated>2007-10-14T12:12:12Z</a:updated>     <a:link href="" />  
  18.    <a:link rel="alternate" type="application/json" href="1;json" />   
  19.   <a:link rel="replies" type="application/atom+xml"     
  20.   href="1;replies" thr:count="10" />     <a:content type="xhtml">    
  21.    <div>         <p>This is the content of the first entry. It contains a picture.</p>     
  22.     <img src="/images/foo.jpg" />       </div>     </a:content>  
  23.    <thr:in-reply-to ref="tag:example.org,2007:/foo/entries/2" />     
  24. <a:category scheme="http://example.org/categories/" term="foo"      
  25.  label="test" xml:lang="en-US" />     <a:category scheme="http://example.org/categories/" term="bar"  
  26.      label="essai" xml:lang="fr" />     <foo:a><foo:b><foo:c d="e">f</foo:c></foo:b></foo:a>  
  27.  </a:entry>    <a:entry xml:base="entries/2" xml:lang="fr">     <a:id>tag:example.org,2007:/foo/entries/2</a:id>   
  28.   <a:title type="text">La première entrée</a:title>     <a:summary type="xhtml">       <div>       
  29.   <p>Il s''agit de la première entrée. Vous pouvez lire         <a href="">est ici</a></p>     
  30.   </div>     </a:summary>     <a:rights type="html">      <p>Copyright &copy; James M Snell</p>  
  31.   </a:rights>     <a:updated>2007-10-14T12:12:11Z</a:updated>     <a:link href="" />   
  32.   <a:link rel="alternate" type="application/json" href="2;json" />     <a:link rel="replies" type="application/atom+xml"     
  33.   href="2;replies" thr:count="10" />     <a:content type="xhtml">       <div>      
  34.    <p>Ceci est le contenu de la première entrée. Il contient une image.</p>      
  35.    <img src="/images/foo.jpg" />       </div>     </a:content>    
  36. <a:category scheme="http://example.org/categories/" term="foo"  
  37.      label="test" xml:lang="en-US" />     <a:category scheme="http://example.org/categories/" term="bar" 
  38.       label="essai" xml:lang="fr" />     <foo:a><foo:b><foo:c d="e">f</foo:c></foo:b></foo:a>   </a:entry> </a:feed> 

本文描述的從 Atom 到 JSON 的序列化技術(shù)能夠生成一個(gè)容易理解、易于使用而且能夠避免丟失重要上下文數(shù)據(jù)的 JSON 表示。清單 31. 對(duì)清單 30 中完整的 Atom 提要文檔進(jìn)行 JSON 序列化

使用 Abdera JSON Writer

本文介紹的技術(shù)已經(jīng)作為 Apache Abdera 項(xiàng)目的一部分實(shí)現(xiàn)了。清單 32 中的代碼演示了 Abdera JSON Writer 的使用。如果想要嘗試 Atom 到 JSON 的轉(zhuǎn)換,請(qǐng)?jiān)L問 Abdera wiki,獲取關(guān)于如何下載最新開發(fā)映像的信息。

結(jié)束語(yǔ)

將數(shù)據(jù)從一種格式轉(zhuǎn)換成另一種格式總是一個(gè)很困難的任務(wù)。將 Atom 這樣豐富和強(qiáng)大的數(shù)據(jù)格式序列化為 JSON 這類簡(jiǎn)單的基本格式,一定會(huì)面臨許多問題。盡管已經(jīng)有許多出色的嘗試,在出現(xiàn)標(biāo)準(zhǔn)的轉(zhuǎn)換方法之前,應(yīng)用程序開發(fā)人員需要處理多種質(zhì)量參差不齊的不兼容序列化方法,本文描述的技術(shù)只是其中的一種。

責(zé)任編輯:chenqingxiang 來(lái)源: 賽迪
相關(guān)推薦

2010-01-07 17:02:27

JSON序列化

2009-12-22 14:31:27

WCF序列化依賴屬性

2013-03-11 13:55:03

JavaJSON

2009-07-29 13:39:02

JSON序列化和反序列ASP.NET AJA

2010-03-19 15:54:21

Java Socket

2021-11-18 07:39:41

Json 序列化Vue

2016-10-20 15:54:08

Python數(shù)據(jù)序列化

2018-01-17 16:38:07

MSONJSON序列化

2011-06-01 15:05:02

序列化反序列化

2022-08-06 08:41:18

序列化反序列化Hessian

2018-03-19 10:20:23

Java序列化反序列化

2010-01-07 17:48:02

JSON結(jié)構(gòu)

2024-10-07 08:26:53

2024-01-30 13:32:51

JSON反序列化序列化

2009-06-14 22:01:27

Java對(duì)象序列化反序列化

2009-08-24 17:14:08

C#序列化

2011-06-01 14:26:11

序列化

2010-01-06 11:14:47

JSON文本

2023-12-13 13:49:52

Python序列化模塊

2009-08-06 11:16:25

C#序列化和反序列化
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)