json.net的使用

前端之家收集整理的这篇文章主要介绍了json.net的使用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

json.net的使用起来很简单的

可以到它的官方网站去下载它的组件(注意版本问题哦)

http://www.codeplex.com/Json/Release/ProjectReleases.aspx?ReleaseId=18825

安装后 引用

  1. usingSystem;
  2. usingSystem.Data;
  3. usingSystem.Configuration;
  4. usingSystem.Web;
  5. usingSystem.Web.Security;
  6. usingSystem.Web.UI;
  7. usingSystem.Web.UI.WebControls;
  8. usingSystem.Web.UI.WebControls.WebParts;
  9. usingSystem.Web.UI.HtmlControls;
  10. usingNewtonsoft.Json;
  11. usingSystem.Collections;
  12. usingNewtonsoft.Json.Utilities;
  13. usingSystem.Runtime.Serialization;
  14. usingSystem.Text;
  15. usingSystem.Collections.Generic;
  16. usingSystem.IO;
  17. publicpartialclass_Default:System.Web.UI.Page
  18. {
  19. publicstaticstringstr="hello";
  20. protectedvoidPage_Load(objectsender,EventArgse)
  21. {
  22. //第一种
  23. BaseClassbs=newBaseClass();
  24. bs.Title="helloworld";
  25. bs.Content="thisisok";
  26. bs.Userip="127.0.0.1";
  27. //第二种
  28. Hashtablehs1=newHashtable();
  29. hs1.Add("username","dwqdq");
  30. hs1.Add("pwd","656");
  31. stringjson1=JavaScriptConvert.SerializeObject(bs);
  32. stringjson2=JavaScriptConvert.SerializeObject(hs1);
  33. Response.Write(json1);
  34. Response.Write(json2);
  35. }
  36. }

BaseClass.cs

  1. usingSystem;
  2. usingSystem.Data;
  3. usingSystem.Configuration;
  4. usingSystem.Web;
  5. usingSystem.Web.Security;
  6. usingSystem.Web.UI;
  7. usingSystem.Web.UI.WebControls;
  8. usingSystem.Web.UI.WebControls.WebParts;
  9. usingSystem.Web.UI.HtmlControls;
  10. ///<summary>
  11. ///BaseClass的摘要说明
  12. ///</summary>
  13. publicclassBaseClass
  14. {
  15. publicBaseClass()
  16. {
  17. //
  18. //TODO:在此处添加构造函数逻辑
  19. //
  20. }
  21. string_title;
  22. publicstringTitle
  23. {
  24. get{return_title;}
  25. set{_title=value;}
  26. }
  27. string_content;
  28. publicstringContent
  29. {
  30. get{return_content;}
  31. set{_content=value;}
  32. }
  33. string_userip;
  34. publicstringUserip
  35. {
  36. get{return_userip;}
  37. set{_userip=value;}
  38. }
  39. }

是不是很简单?

原文链接:https://www.f2er.com/json/290844.html

猜你在找的Json相关文章