0

0

使用Json.net的方法

php中世界最好的语言

php中世界最好的语言

发布时间:2018-04-24 17:29:12

|

3085人浏览过

|

来源于php中文网

原创

这次给大家带来使用Json.net的方法,使用Json.net的方法的注意事项有哪些,下面就是实战案例,一起来看一下。

Json.net 常用使用小结(推荐)

using System;
using System.Linq;
using System.Collections.Generic;
namespace microstore
{
  public interface IPerson
  {
    string FirstName
    {
      get;
      set;
    }
    string LastName
    {
      get;
      set;
    }
    DateTime BirthDate
    {
      get;
      set;
    }
  }
  public class Employee : IPerson
  {
    public string FirstName
    {
      get;
      set;
    }
    public string LastName
    {
      get;
      set;
    }
    public DateTime BirthDate
    {
      get;
      set;
    }
    public string Department
    {
      get;
      set;
    }
    public string JobTitle
    {
      get;
      set;
    }
  }
  public class PersonConverter : Newtonsoft.Json.Converters.CustomCreationConverter
  {
    //重写abstract class CustomCreationConverter的Create方法
    public override IPerson Create(Type objectType)
    {
      return new Employee();
    }
  }
  public partial class testjson : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      //if (!IsPostBack)
      //  TestJson();
    }
    #region 序列化
    public string TestJsonSerialize()
    {
      Product product = new Product();
      product.Name = "Apple";
      product.Expiry = DateTime.Now.AddDays(3).ToString("yyyy-MM-dd hh:mm:ss");
      product.Price = 3.99M;
      //product.Sizes = new string[] { "Small", "Medium", "Large" };
      //string json = Newtonsoft.Json.JsonConvert.SerializeObject(product); //没有缩进输出
      string json = Newtonsoft.Json.JsonConvert.SerializeObject(product, Newtonsoft.Json.Formatting.Indented);
      //string json = Newtonsoft.Json.JsonConvert.SerializeObject(
      //  product, 
      //  Newtonsoft.Json.Formatting.Indented,
      //  new Newtonsoft.Json.JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore }
      //);
      return string.Format("

{0}

", json); } public string TestListJsonSerialize() { Product product = new Product(); product.Name = "Apple"; product.Expiry = DateTime.Now.AddDays(3).ToString("yyyy-MM-dd hh:mm:ss"); product.Price = 3.99M; product.Sizes = new string[] { "Small", "Medium", "Large" }; List plist = new List(); plist.Add(product); plist.Add(product); string json = Newtonsoft.Json.JsonConvert.SerializeObject(plist, Newtonsoft.Json.Formatting.Indented); return string.Format("

{0}

", json); } #endregion #region 反序列化 public string TestJsonDeserialize() { string strjson = "{\"Name\":\"Apple\",\"Expiry\":\"2014-05-03 10:20:59\",\"Price\":3.99,\"Sizes\":[\"Small\",\"Medium\",\"Large\"]}"; Product p = Newtonsoft.Json.JsonConvert.DeserializeObject(strjson); string template = @"

  • {0}
  • {1}
  • {2}
  • {3}

"; return string.Format(template, p.Name, p.Expiry, p.Price.ToString(), string.Join(",", p.Sizes)); } public string TestListJsonDeserialize() { string strjson = "{\"Name\":\"Apple\",\"Expiry\":\"2014-05-03 10:20:59\",\"Price\":3.99,\"Sizes\":[\"Small\",\"Medium\",\"Large\"]}"; List plist = Newtonsoft.Json.JsonConvert.DeserializeObject>(string.Format("[{0},{1}]", strjson, strjson)); string template = @"

  • {0}
  • {1}
  • {2}
  • {3}

"; System.Text.StringBuilder strb = new System.Text.StringBuilder(); plist.ForEach(x => strb.AppendLine( string.Format(template, x.Name, x.Expiry, x.Price.ToString(), string.Join(",", x.Sizes)) ) ); return strb.ToString(); } #endregion #region 自定义反序列化 public string TestListCustomDeserialize() { string strJson = "[ { \"FirstName\": \"Maurice\", \"LastName\": \"Moss\", \"BirthDate\": \"1981-03-08T00:00Z\", \"Department\": \"IT\", \"JobTitle\": \"Support\" }, { \"FirstName\": \"Jen\", \"LastName\": \"Barber\", \"BirthDate\": \"1985-12-10T00:00Z\", \"Department\": \"IT\", \"JobTitle\": \"Manager\" } ] "; List people = Newtonsoft.Json.JsonConvert.DeserializeObject>(strJson, new PersonConverter()); IPerson person = people[0]; string template = @"

  • 当前List[x]对象类型:{0}
  • FirstName:{1}
  • LastName:{2}
  • BirthDate:{3}
  • Department:{4}
  • JobTitle:{5}

"; System.Text.StringBuilder strb = new System.Text.StringBuilder(); people.ForEach(x => strb.AppendLine( string.Format( template, person.GetType().ToString(), x.FirstName, x.LastName, x.BirthDate.ToString(), ((Employee)x).Department, ((Employee)x).JobTitle ) ) ); return strb.ToString(); } #endregion #region 反序列化成Dictionary public string TestDeserialize2Dic() { //string json = @"{""key1"":""zhangsan"",""key2"":""lisi""}"; //string json = "{\"key1\":\"zhangsan\",\"key2\":\"lisi\"}"; string json = "{key1:\"zhangsan\",key2:\"lisi\"}"; Dictionary dic = Newtonsoft.Json.JsonConvert.DeserializeObject>(json); string template = @"
  • key:{0},value:{1}
  • "; System.Text.StringBuilder strb = new System.Text.StringBuilder(); strb.Append("Dictionary长度" + dic.Count.ToString() + "
      "); dic.AsQueryable().ToList().ForEach(x => { strb.AppendLine(string.Format(template, x.Key, x.Value)); }); strb.Append("
    "); return strb.ToString(); } #endregion #region NullValueHandling特性 public class Movie { public string Name { get; set; } public string Description { get; set; } public string Classification { get; set; } public string Studio { get; set; } public DateTime? ReleaseDate { get; set; } public List ReleaseCountries { get; set; } } /// /// 完整序列化输出 /// public string CommonSerialize() { Movie movie = new Movie(); movie.Name = "Bad Boys III"; movie.Description = "It's no Bad Boys"; string included = Newtonsoft.Json.JsonConvert.SerializeObject( movie, Newtonsoft.Json.Formatting.Indented, //缩进 new Newtonsoft.Json.JsonSerializerSettings { } ); return included; } /// /// 忽略空(Null)对象输出 /// /// public string IgnoredSerialize() { Movie movie = new Movie(); movie.Name = "Bad Boys III"; movie.Description = "It's no Bad Boys"; string included = Newtonsoft.Json.JsonConvert.SerializeObject( movie, Newtonsoft.Json.Formatting.Indented, //缩进 new Newtonsoft.Json.JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore } ); return included; } #endregion public class Product { public string Name { get; set; } public string Expiry { get; set; } public Decimal Price { get; set; } public string[] Sizes { get; set; } } #region DefaultValueHandling默认值 public class Invoice { public string Company { get; set; } public decimal Amount { get; set; } // false is default value of bool public bool Paid { get; set; } // null is default value of nullable public DateTime? PaidDate { get; set; } // customize default values [System.ComponentModel.DefaultValue(30)] public int FollowUpDays { get; set; } [System.ComponentModel.DefaultValue("")] public string FollowUpEmailAddress { get; set; } } public void GG() { Invoice invoice = new Invoice { Company = "Acme Ltd.", Amount = 50.0m, Paid = false, FollowUpDays = 30, FollowUpEmailAddress = string.Empty, PaidDate = null }; string included = Newtonsoft.Json.JsonConvert.SerializeObject( invoice, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings { } ); // { // "Company": "Acme Ltd.", // "Amount": 50.0, // "Paid": false, // "PaidDate": null, // "FollowUpDays": 30, // "FollowUpEmailAddress": "" // } string ignored = Newtonsoft.Json.JsonConvert.SerializeObject( invoice, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings { DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore } ); // { // "Company": "Acme Ltd.", // "Amount": 50.0 // } } #endregion #region JsonIgnoreAttribute and DataMemberAttribute 特性 public string OutIncluded() { Car car = new Car { Model = "zhangsan", Year = DateTime.Now, Features = new List { "aaaa", "bbbb", "cccc" }, LastModified = DateTime.Now.AddDays(5) }; return Newtonsoft.Json.JsonConvert.SerializeObject(car, Newtonsoft.Json.Formatting.Indented); } public string OutIncluded2() { Computer com = new Computer { Name = "zhangsan", SalePrice = 3999m, Manufacture = "red", StockCount = 5, WholeSalePrice = 34m, NextShipmentDate = DateTime.Now.AddDays(5) }; return Newtonsoft.Json.JsonConvert.SerializeObject(com, Newtonsoft.Json.Formatting.Indented); } public class Car { // included in JSON public string Model { get; set; } public DateTime Year { get; set; } public List Features { get; set; } // ignored [Newtonsoft.Json.JsonIgnore] public DateTime LastModified { get; set; } } //在nt3.5中需要添加System.Runtime.Serialization.dll引用 [System.Runtime.Serialization.DataContract] public class Computer { // included in JSON [System.Runtime.Serialization.DataMember] public string Name { get; set; } [System.Runtime.Serialization.DataMember] public decimal SalePrice { get; set; } // ignored public string Manufacture { get; set; } public int StockCount { get; set; } public decimal WholeSalePrice { get; set; } public DateTime NextShipmentDate { get; set; } } #endregion #region IContractResolver特性 public class Book { public string BookName { get; set; } public decimal BookPrice { get; set; } public string AuthorName { get; set; } public int AuthorAge { get; set; } public string AuthorCountry { get; set; } } public void KK() { Book book = new Book { BookName = "The Gathering Storm", BookPrice = 16.19m, AuthorName = "Brandon Sanderson", AuthorAge = 34, AuthorCountry = "United States of America" }; string startingWithA = Newtonsoft.Json.JsonConvert.SerializeObject( book, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings { ContractResolver = new DynamicContractResolver('A') } ); // { // "AuthorName": "Brandon Sanderson", // "AuthorAge": 34, // "AuthorCountry": "United States of America" // } string startingWithB = Newtonsoft.Json.JsonConvert.SerializeObject( book, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings { ContractResolver = new DynamicContractResolver('B') } ); // { // "BookName": "The Gathering Storm", // "BookPrice": 16.19 // } } public class DynamicContractResolver : Newtonsoft.Json.Serialization.DefaultContractResolver { private readonly char _startingWithChar; public DynamicContractResolver(char startingWithChar) { _startingWithChar = startingWithChar; } protected override IList CreateProperties(Type type, Newtonsoft.Json.MemberSerialization memberSerialization) { IList properties = base.CreateProperties(type, memberSerialization); // only serializer properties that start with the specified character properties = properties.Where(p => p.PropertyName.StartsWith(_startingWithChar.ToString())).ToList(); return properties; } } #endregion //... } } #region Serializing Partial JSON Fragment Example public class SearchResult { public string Title { get; set; } public string Content { get; set; } public string Url { get; set; } } public string SerializingJsonFragment() { #region string googleSearchText = @"{ 'responseData': { 'results': [{ 'GsearchResultClass': 'GwebSearch', 'unescapedUrl': 'http://en.wikipedia.org/wiki/Paris_Hilton', 'url': 'http://en.wikipedia.org/wiki/Paris_Hilton', 'visibleUrl': 'en.wikipedia.org', 'cacheUrl': 'http://www.google.com/search?q=cache:TwrPfhd22hYJ:en.wikipedia.org', 'title': 'Paris Hilton - Wikipedia, the free encyclopedia', 'titleNoFormatting': 'Paris Hilton - Wikipedia, the free encyclopedia', 'content': '[1] In 2006, she released her debut album...' }, { 'GsearchResultClass': 'GwebSearch', 'unescapedUrl': 'http://www.imdb.com/name/nm0385296/', 'url': 'http://www.imdb.com/name/nm0385296/', 'visibleUrl': 'www.imdb.com', 'cacheUrl': 'http://www.google.com/search?q=cache:1i34KkqnsooJ:www.imdb.com', 'title': 'Paris Hilton', 'titleNoFormatting': 'Paris Hilton', 'content': 'Self: Zoolander. Socialite Paris Hilton...' }], 'cursor': { 'pages': [{ 'start': '0', 'label': 1 }, { 'start': '4', 'label': 2 }, { 'start': '8', 'label': 3 }, { 'start': '12', 'label': 4 }], 'estimatedResultCount': '59600000', 'currentPageIndex': 0, 'moreResultsUrl': 'http://www.google.com/search?oe=utf8&ie=utf8...' } }, 'responseDetails': null, 'responseStatus': 200 }"; #endregion Newtonsoft.Json.Linq.JObject googleSearch = Newtonsoft.Json.Linq.JObject.Parse(googleSearchText); // get JSON result objects into a list List listJToken = googleSearch["responseData"]["results"].Children().ToList(); System.Text.StringBuilder strb = new System.Text.StringBuilder(); string template = @"
    • Title:{0}
    • Content: {1}
    • Url:{2}
    "; listJToken.ForEach(x => { // serialize JSON results into .NET objects SearchResult searchResult = Newtonsoft.Json.JsonConvert.DeserializeObject(x.ToString()); strb.AppendLine(string.Format(template, searchResult.Title, searchResult.Content, searchResult.Url)); }); return strb.ToString(); } #endregion #region ShouldSerialize public class CC { public string Name { get; set; } public CC Manager { get; set; } //http://msdn.microsoft.com/en-us/library/53b8022e.aspx public bool ShouldSerializeManager() { // don't serialize the Manager property if an employee is their own manager return (Manager != this); } } public string ShouldSerializeTest() { //create Employee mike CC mike = new CC(); mike.Name = "Mike Manager"; //create Employee joe CC joe = new CC(); joe.Name = "Joe Employee"; joe.Manager = mike; //set joe'Manager = mike // mike is his own manager // ShouldSerialize will skip this property mike.Manager = mike; return Newtonsoft.Json.JsonConvert.SerializeObject(new[] { joe, mike }, Newtonsoft.Json.Formatting.Indented); } #endregion //驼峰结构输出(小写打头,后面单词大写) public string JJJ() { Product product = new Product { Name = "Widget", Expiry = DateTime.Now.ToString(), Price = 9.99m, Sizes = new[] { "Small", "Medium", "Large" } }; string json = Newtonsoft.Json.JsonConvert.SerializeObject( product, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings { ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() } ); return json; //{ // "name": "Widget", // "expiryDate": "2010-12-20T18:01Z", // "price": 9.99, // "sizes": [ // "Small", // "Medium", // "Large" // ] //} } #region ITraceWriter public class Staff { public string Name { get; set; } public List Roles { get; set; } public DateTime StartDate { get; set; } } public void KKKK() { Staff staff = new Staff(); staff.Name = "Arnie Admin"; staff.Roles = new List { "Administrator" }; staff.StartDate = new DateTime(2000, 12, 12, 12, 12, 12, DateTimeKind.Utc); Newtonsoft.Json.Serialization.ITraceWriter traceWriter = new Newtonsoft.Json.Serialization.MemoryTraceWriter(); Newtonsoft.Json.JsonConvert.SerializeObject( staff, new Newtonsoft.Json.JsonSerializerSettings { TraceWriter = traceWriter, Converters = { new Newtonsoft.Json.Converters.JavaScriptDateTimeConverter() } } ); Console.WriteLine(traceWriter); // 2012-11-11T12:08:42.761 Info Started serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''. // 2012-11-11T12:08:42.785 Info Started serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'. // 2012-11-11T12:08:42.791 Info Finished serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'. // 2012-11-11T12:08:42.797 Info Started serializing System.Collections.Generic.List`1[System.String]. Path 'Roles'. // 2012-11-11T12:08:42.798 Info Finished serializing System.Collections.Generic.List`1[System.String]. Path 'Roles'. // 2012-11-11T12:08:42.799 Info Finished serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''. // 2013-05-18T21:38:11.255 Verbose Serialized JSON: // { // "Name": "Arnie Admin", // "StartDate": new Date( // 976623132000 // ), // "Roles": [ // "Administrator" // ] // } } #endregion public string TestReadJsonFromFile() { Linq2Json l2j = new Linq2Json(); Newtonsoft.Json.Linq.JObject jarray = l2j.GetJObject4(); return jarray.ToString(); } using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace microstore { public class Linq2Json { #region GetJObject //Parsing a JSON Object from text public Newtonsoft.Json.Linq.JObject GetJObject() { string json = @"{ CPU: 'Intel', Drives: [ 'DVD read/writer', '500 gigabyte hard drive' ] }"; Newtonsoft.Json.Linq.JObject jobject = Newtonsoft.Json.Linq.JObject.Parse(json); return jobject; } /* * //example:=> * Linq2Json l2j = new Linq2Json(); Newtonsoft.Json.Linq.JObject jobject = l2j.GetJObject2(Server.MapPath("json/Person.json")); //return Newtonsoft.Json.JsonConvert.SerializeObject(jobject, Newtonsoft.Json.Formatting.Indented); return jobject.ToString(); */ //Loading JSON from a file public Newtonsoft.Json.Linq.JObject GetJObject2(string jsonPath) { using (System.IO.StreamReader reader = System.IO.File.OpenText(jsonPath)) { Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.Linq.JToken.ReadFrom(new Newtonsoft.Json.JsonTextReader(reader)); return jobject; } } //Creating JObject public Newtonsoft.Json.Linq.JObject GetJObject3() { List posts = GetPosts(); Newtonsoft.Json.Linq.JObject jobject = Newtonsoft.Json.Linq.JObject.FromObject(new { channel = new { title = "James Newton-King", link = "http://james.newtonking.com", description = "James Newton-King's blog.", item = from p in posts orderby p.Title select new { title = p.Title, description = p.Description, link = p.Link, category = p.Category } } }); return jobject; } /* { "channel": { "title": "James Newton-King", "link": "http://james.newtonking.com", "description": "James Newton-King's blog.", "item": [{ "title": "jewron", "description": "4546fds", "link": "http://www.baidu.com", "category": "jhgj" }, { "title": "jofdsn", "description": "mdsfan", "link": "http://www.baidu.com", "category": "6546" }, { "title": "jokjn", "description": "m3214an", "link": "http://www.baidu.com", "category": "hg425" }, { "title": "jon", "description": "man", "link": "http://www.baidu.com", "category": "goodman" }] } } */ //Creating JObject public Newtonsoft.Json.Linq.JObject GetJObject4() { List posts = GetPosts(); Newtonsoft.Json.Linq.JObject rss = new Newtonsoft.Json.Linq.JObject( new Newtonsoft.Json.Linq.JProperty("channel", new Newtonsoft.Json.Linq.JObject( new Newtonsoft.Json.Linq.JProperty("title", "James Newton-King"), new Newtonsoft.Json.Linq.JProperty("link", "http://james.newtonking.com"), new Newtonsoft.Json.Linq.JProperty("description", "James Newton-King's blog."), new Newtonsoft.Json.Linq.JProperty("item", new Newtonsoft.Json.Linq.JArray( from p in posts orderby p.Title select new Newtonsoft.Json.Linq.JObject( new Newtonsoft.Json.Linq.JProperty("title", p.Title), new Newtonsoft.Json.Linq.JProperty("description", p.Description), new Newtonsoft.Json.Linq.JProperty("link", p.Link), new Newtonsoft.Json.Linq.JProperty("category", new Newtonsoft.Json.Linq.JArray( from c in p.Category select new Newtonsoft.Json.Linq.JValue(c) ) ) ) ) ) ) ) ); return rss; } /* { "channel": { "title": "James Newton-King", "link": "http://james.newtonking.com", "description": "James Newton-King's blog.", "item": [{ "title": "jewron", "description": "4546fds", "link": "http://www.baidu.com", "category": ["j", "h", "g", "j"] }, { "title": "jofdsn", "description": "mdsfan", "link": "http://www.baidu.com", "category": ["6", "5", "4", "6"] }, { "title": "jokjn", "description": "m3214an", "link": "http://www.baidu.com", "category": ["h", "g", "4", "2", "5"] }, { "title": "jon", "description": "man", "link": "http://www.baidu.com", "category": ["g", "o", "o", "d", "m", "a", "n"] }] } } */ public class Post { public string Title { get; set; } public string Description { get; set; } public string Link { get; set; } public string Category { get; set; } } private List GetPosts() { List listp = new List() { new Post{Title="jon",Description="man",Link="http://www.baidu.com",Category="goodman"}, new Post{Title="jofdsn",Description="mdsfan",Link="http://www.baidu.com",Category="6546"}, new Post{Title="jewron",Description="4546fds",Link="http://www.baidu.com",Category="jhgj"}, new Post{Title="jokjn",Description="m3214an",Link="http://www.baidu.com",Category="hg425"} }; return listp; } #endregion #region GetJArray /* * //example:=> * Linq2Json l2j = new Linq2Json(); Newtonsoft.Json.Linq.JArray jarray = l2j.GetJArray(); return Newtonsoft.Json.JsonConvert.SerializeObject(jarray, Newtonsoft.Json.Formatting.Indented); //return jarray.ToString(); */ //Parsing a JSON Array from text public Newtonsoft.Json.Linq.JArray GetJArray() { string json = @"[ 'Small', 'Medium', 'Large' ]"; Newtonsoft.Json.Linq.JArray jarray = Newtonsoft.Json.Linq.JArray.Parse(json); return jarray; } //Creating JArray public Newtonsoft.Json.Linq.JArray GetJArray2() { Newtonsoft.Json.Linq.JArray array = new Newtonsoft.Json.Linq.JArray(); Newtonsoft.Json.Linq.JValue text = new Newtonsoft.Json.Linq.JValue("Manual text"); Newtonsoft.Json.Linq.JValue date = new Newtonsoft.Json.Linq.JValue(new DateTime(2000, 5, 23)); //add to JArray array.Add(text); array.Add(date); return array; } #endregion //待续... } }

    测试效果:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="testjson.aspx.cs" Inherits="microstore.testjson" %>
    
    
    
      
      
    
      
      

    序列化对象

    表现1:
    <%=TestJsonSerialize()%> <%=TestListJsonSerialize() %> 表现2:
    <%=TestListJsonSerialize2() %>

    反序列化对象

    单个对象

    <%=TestJsonDeserialize() %>

    多个对象

    <%=TestListJsonDeserialize() %>

    反序列化成数据字典Dictionary

    VALL-E
    VALL-E

    VALL-E是一种用于文本到语音生成 (TTS) 的语言建模方法

    下载
    <%=TestDeserialize2Dic() %>

    自定义反序列化

    <%=TestListCustomDeserialize()%>

    序列化输出的忽略特性

    NullValueHandling特性忽略=>
    <%=CommonSerialize() %>
    <%=IgnoredSerialize()%>

    属性标记忽略=>
    <%=OutIncluded() %>
    <%=OutIncluded2() %>

    Serializing Partial JSON Fragments

    <%=SerializingJsonFragment() %>

    ShouldSerialize

    <%=ShouldSerializeTest() %>
    <%=JJJ() %>

    <%=TestReadJsonFromFile() %>

    显示:

    序列化对象

    表现1:

    { "Name": "Apple", "Expiry": "2014-05-04 02:08:58", "Price": 3.99, "Sizes": null }
    [ { "Name": "Apple", "Expiry": "2014-05-04 02:08:58", "Price": 3.99, "Sizes": [ "Small", "Medium", "Large" ] }, { "Name": "Apple", "Expiry": "2014-05-04 02:08:58", "Price": 3.99, "Sizes": [ "Small", "Medium", "Large" ] } ]

     表现2:

    [ { "Name": "Apple", "Expiry": "2014-05-04 02:08:58", "Price": 3.99, "Sizes": [ "Small", "Medium", "Large" ] }, { "Name": "Apple", "Expiry": "2014-05-04 02:08:58", "Price": 3.99, "Sizes": [ "Small", "Medium", "Large" ] } ]

    相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

    推荐阅读:

    ajax获得json数据后格式怎么转换

    ajax三种解析模式使用详解

    相关专题

    更多
    php源码安装教程大全
    php源码安装教程大全

    本专题整合了php源码安装教程,阅读专题下面的文章了解更多详细内容。

    65

    2025.12.31

    php网站源码教程大全
    php网站源码教程大全

    本专题整合了php网站源码相关教程,阅读专题下面的文章了解更多详细内容。

    43

    2025.12.31

    视频文件格式
    视频文件格式

    本专题整合了视频文件格式相关内容,阅读专题下面的文章了解更多详细内容。

    35

    2025.12.31

    不受国内限制的浏览器大全
    不受国内限制的浏览器大全

    想找真正自由、无限制的上网体验?本合集精选2025年最开放、隐私强、访问无阻的浏览器App,涵盖Tor、Brave、Via、X浏览器、Mullvad等高自由度工具。支持自定义搜索引擎、广告拦截、隐身模式及全球网站无障碍访问,部分更具备防追踪、去谷歌化、双内核切换等高级功能。无论日常浏览、隐私保护还是突破地域限制,总有一款适合你!

    41

    2025.12.31

    出现404解决方法大全
    出现404解决方法大全

    本专题整合了404错误解决方法大全,阅读专题下面的文章了解更多详细内容。

    204

    2025.12.31

    html5怎么播放视频
    html5怎么播放视频

    想让网页流畅播放视频?本合集详解HTML5视频播放核心方法!涵盖<video>标签基础用法、多格式兼容(MP4/WebM/OGV)、自定义播放控件、响应式适配及常见浏览器兼容问题解决方案。无需插件,纯前端实现高清视频嵌入,助你快速打造现代化网页视频体验。

    9

    2025.12.31

    关闭win10系统自动更新教程大全
    关闭win10系统自动更新教程大全

    本专题整合了关闭win10系统自动更新教程大全,阅读专题下面的文章了解更多详细内容。

    8

    2025.12.31

    阻止电脑自动安装软件教程
    阻止电脑自动安装软件教程

    本专题整合了阻止电脑自动安装软件教程,阅读专题下面的文章了解更多详细教程。

    3

    2025.12.31

    html5怎么使用
    html5怎么使用

    想快速上手HTML5开发?本合集为你整理最实用的HTML5使用指南!涵盖HTML5基础语法、主流框架(如Bootstrap、Vue、React)集成方法,以及无需安装、直接在线编辑运行的平台推荐(如CodePen、JSFiddle)。无论你是新手还是进阶开发者,都能轻松掌握HTML5网页制作、响应式布局与交互功能开发,零配置开启高效前端编程之旅!

    2

    2025.12.31

    热门下载

    更多
    网站特效
    /
    网站源码
    /
    网站素材
    /
    前端模板

    精品课程

    更多
    相关推荐
    /
    热门推荐
    /
    最新课程
    React 教程
    React 教程

    共58课时 | 3.2万人学习

    TypeScript 教程
    TypeScript 教程

    共19课时 | 1.9万人学习

    Bootstrap 5教程
    Bootstrap 5教程

    共46课时 | 2.7万人学习

    关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
    php中文网:公益在线php培训,帮助PHP学习者快速成长!
    关注服务号 技术交流群
    PHP中文网订阅号
    每天精选资源文章推送

    Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号