记一次解析XML转对象的笔记
项目中调用第三方API,返回格式是XML字符串,需要将XML反序列化为对象,格式如下:
<?xml version="1.0"?>
<Response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" totalCount="" resultCode="ABC" resultMessage="测试">
<profile lastName="李" firstName="爽" dateOfBirth="XX0816" age="" gender="" address="浙江省 杭州富阳市 东州工业园区3号路1号杭州龙盛工贸有限公" email="htlslll@163.com" cellEmail="" socialMedia="" homePhone="" cellPhone="" contactabiltyMail="" contactabiltyEmail="" contactabiltyCellEmail="" contactabiltyHomePhone="" contactabiltyCellPhone="" contactabiltyText="" contactabiltySocialMedia="" vipLevel="" memberId="OC540C00016824" saAccount="" classa="小姐" homeStoreCode="OC54" />
<purchaseHistory>
<departmentPurchase totalLifeTimeSale="" totalTYAmount="" lastTxn="" totalTYUnitCnt="" firstTxn="">
<department categoryName="D08" tyAmount="" tyUnitCnt="" />
<department categoryName="D01" tyAmount="" tyUnitCnt="" />
<department categoryName="D02" tyAmount="" tyUnitCnt="" />
</departmentPurchase>
<ratePurchase totalLyAmount="" totalLyRate="" totalTyAmount="" totalTyRate="" totalLifeTimeAmount="" totalLifeTimeRate="">
<rate categoryName="Retail" lyAmount="" lyRate="" lyToDate="" tyAmount="" tyRate="" tyToDate="" lifeTimeAmount="" lifeTimeRate="" lyTyChange="" />
</ratePurchase>
<storeRatePurchase>
<storeRate />
</storeRatePurchase>
</purchaseHistory>
<vipStatus issueDate="" issueShop="OC54" ptsToUpgrade="" expiryDate="" upgradeShop="" ptsToRenew="" />
<comments comment="第一场雪" />
</Response>
按照这个格式我需要定义相应的对象来接收,定义如下:
/// <summary>
///
/// </summary>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false, ElementName = "Response")]
public class Response
{
[System.Xml.Serialization.XmlAttributeAttribute()]
public string totalCount { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string resultCode { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string resultMessage { get; set; } [System.Xml.Serialization.XmlElementAttribute("profile", typeof(profile))]
public profile profile { get; set; } [System.Xml.Serialization.XmlElementAttribute("purchaseHistory", typeof(purchaseHistory))]
public purchaseHistory purchaseHistory { get; set; } [System.Xml.Serialization.XmlElementAttribute("vipStatus", typeof(vipStatus))]
public vipStatus vipStatus { get; set; } [System.Xml.Serialization.XmlElementAttribute("comments", typeof(comments))]
public comments comments { get; set; }
} [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
public class profile
{
[System.Xml.Serialization.XmlAttributeAttribute()]
public string lastName { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string firstName { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string dateOfBirth { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string age { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string gender { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string address { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string email { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string cellEmail { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string socialMedia { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string homePhone { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string cellPhone { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string contactabiltyMail { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string contactabiltyEmail { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string contactabiltyCellEmail { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string contactabiltyHomePhone { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string contactabiltyCellPhone { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string contactabiltyText { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string contactabiltySocialMedia { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string vipLevel { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string memberId { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string saAccount { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string classa { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string homeStoreCode { get; set; }
} [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
public class purchaseHistory
{ [System.Xml.Serialization.XmlElementAttribute("departmentPurchase", typeof(departmentPurchase))]
public departmentPurchase departmentPurchase { get; set; } [System.Xml.Serialization.XmlElementAttribute("ratePurchase", typeof(ratePurchase))]
public ratePurchase ratePurchase { get; set; } [System.Xml.Serialization.XmlElementAttribute("storeRatePurchase", typeof(storeRatePurchase))]
public storeRatePurchase storeRatePurchase { get; set; }
} [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
public class departmentPurchase
{
[System.Xml.Serialization.XmlAttributeAttribute()]
public string totalTYAmount { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string totalTYUnitCnt { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string firstTxn { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string lastTxn { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string totalLifeTimeSale { get; set; } [System.Xml.Serialization.XmlElementAttribute("department", typeof(List<department>), Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = )]
public List<department> department { get; set; }
} [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
public class department
{
[System.Xml.Serialization.XmlAttributeAttribute()]
public string categoryName { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string tyAmount { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string tyUnitCnt { get; set; }
} [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
public class ratePurchase
{
[System.Xml.Serialization.XmlAttributeAttribute()]
public string totalLyAmount { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string totalLyRate { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string totalTyAmount { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string totalTyRate { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string totalLifeTimeAmount { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string totalLifeTimeRate { get; set; } [System.Xml.Serialization.XmlElementAttribute("rate", typeof(rate))]
public rate rate { get; set; }
} [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
public class rate
{
[System.Xml.Serialization.XmlAttributeAttribute()]
public string categoryName { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string lyAmount { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string lyRate { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string lyToDate { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string tyAmount { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string tyRate { get; set; }
[System.Xml.Serialization.XmlAttributeAttribute()] public string tyToDate { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string lifeTimeAmount { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string lifeTimeRate { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string lyTyChange { get; set; } } [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
public class storeRatePurchase
{
public string storeRate { get; set; }
} [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
public class vipStatus
{
[System.Xml.Serialization.XmlAttributeAttribute()]
public string issueDate { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string issueShop { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string ptsToUpgrade { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string expiryDate { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string upgradeShop { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()]
public string ptsToRenew { get; set; }
} [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
public class comments
{
[System.Xml.Serialization.XmlAttributeAttribute()]
public string comment { get; set; }
}
解析代码如下
private static System.Xml.Serialization.XmlSerializer Serializer;
/// <summary>
/// 指定XML字符串序列化成对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="xml"></param>
/// <returns></returns>
public static T DeserializeForXml<T>(string xml) where T : class, new()
{
System.IO.StringReader stringReader = null;
try
{
Serializer = Serializer ?? new XmlSerializer(typeof(T));
stringReader = new StringReader(xml);
T result = Serializer.Deserialize(stringReader) as T;
return result;
}
finally
{
if ((stringReader != null))
{
stringReader.Dispose();
}
}
}
调用方式:
var rpXML = AcxiomXMLHelper.DeserializeForXml<CustomerDetails.Response>(returnXML);
好了,接下来就出现了问题
departmentPurchase 下面的department始终是没有数据,调试好久都找不到问题出现在哪里。
尝试找解决的办法,先实例化一个Response对象序列化后写入文件,再将文件内容读出来反序列化出来
Response response = new Response
{
totalCount = "",
resultCode = "ABC",
resultMessage = "测试",
profile = new profile { lastName = "李", firstName = "爽", dateOfBirth = "XX0816", age = "", gender = "", address = "浙江省 杭州富阳市 东州工业园区3号路1号杭州龙盛工贸有限公", email = "htlslll@163.com", cellEmail = "", socialMedia = "", homePhone = "", cellPhone = "", contactabiltyMail = "", contactabiltyEmail = "", contactabiltyCellEmail = "", contactabiltyHomePhone = "", contactabiltyCellPhone = "", contactabiltyText = "", contactabiltySocialMedia = "", vipLevel = "", memberId = "OC540C00016824", saAccount = "", classa = "小姐", homeStoreCode = "OC54" },
comments = new comments { comment = "第一场雪" },
purchaseHistory = new purchaseHistory
{
departmentPurchase = new departmentPurchase
{
totalTYAmount = "",
totalTYUnitCnt = "",
firstTxn = "",
lastTxn = "",
totalLifeTimeSale = "",
department = new List<department> {
new department { categoryName = "D08", tyAmount = "", tyUnitCnt = "" },
new department { categoryName = "D01", tyAmount = "", tyUnitCnt = "" },
new department { categoryName = "D02", tyAmount = "", tyUnitCnt = "" }
}
},
ratePurchase = new ratePurchase
{
totalLyAmount = "",
totalLyRate = "",
totalTyAmount = "",
totalTyRate = "",
totalLifeTimeAmount = "",
totalLifeTimeRate = "",
rate = new rate { categoryName = "Retail", lyAmount = "", lyRate = "", lyToDate = "", tyAmount = "", tyRate = "", tyToDate = "", lifeTimeAmount = "", lifeTimeRate = "", lyTyChange = "" }
},
storeRatePurchase = new storeRatePurchase { storeRate = string.Empty }
},
vipStatus = new vipStatus { issueDate = "", issueShop = "OC54", ptsToUpgrade = "", expiryDate = "", upgradeShop = "", ptsToRenew = "" }
}; FileStream stream = new FileStream(@"d:\xmlFormat.xml", FileMode.Create);
XmlSerializer xmlserilize = new XmlSerializer(typeof(Response));
xmlserilize.Serialize(stream, response); stream.Close(); using (FileStream xmlStream = new FileStream(@"d:\xmlFormat.xml", FileMode.Open))
{
using (XmlReader xmlReader = XmlReader.Create(xmlStream))
{
XmlSerializer serializer = new XmlSerializer(typeof(Response));
Response res = serializer.Deserialize(xmlReader) as Response;
}
}
代码中res是反序列化的结果,数据都正确。这就有点恼火了,怎么办呢?
比较我生成的文件和API返回的XML:
下面是我生成的XML格式
<Response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" totalCount="" resultCode="ABC" resultMessage="测试">
<profile lastName="李" firstName="爽" dateOfBirth="XX0816" age="" gender="" address="浙江省 杭州富阳市 东州工业园区3号路1号杭州龙盛工贸有限公" email="htlslll@163.com" cellEmail="" socialMedia="" homePhone="" cellPhone="" contactabiltyMail="" contactabiltyEmail="" contactabiltyCellEmail="" contactabiltyHomePhone="" contactabiltyCellPhone="" contactabiltyText="" contactabiltySocialMedia="" vipLevel="" memberId="OC540C00016824" saAccount="" classa="小姐" homeStoreCode="OC54" />
<purchaseHistory>
<departmentPurchase totalLifeTimeSale="" totalTYAmount="" lastTxn="" totalTYUnitCnt="" firstTxn="">
<department>
<department categoryName="D08" tyAmount="" tyUnitCnt="" />
<department categoryName="D01" tyAmount="" tyUnitCnt="" />
<department categoryName="D02" tyAmount="" tyUnitCnt="" />
</department>
</departmentPurchase>
<ratePurchase totalLyAmount="" totalLyRate="" totalTyAmount="" totalTyRate="" totalLifeTimeAmount="" totalLifeTimeRate="">
<rate categoryName="Retail" lyAmount="" lyRate="" lyToDate="" tyAmount="" tyRate="" tyToDate="" lifeTimeAmount="" lifeTimeRate="" lyTyChange="" />
</ratePurchase>
<storeRatePurchase>
<storeRate />
</storeRatePurchase>
</purchaseHistory>
<vipStatus issueDate="" issueShop="OC54" ptsToUpgrade="" expiryDate="" upgradeShop="" ptsToRenew="" />
<comments comment="第一场雪" />
</Response>
仔细比对发现问题
在departmentPurchase 节点下我多了一层department节点,可我是按照接口的结果定义的对象啊
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
public class departmentPurchase
{
[System.Xml.Serialization.XmlAttributeAttribute()]
public string totalTYAmount { get; set; }
[System.Xml.Serialization.XmlAttributeAttribute()]
public string totalTYUnitCnt { get; set; }
[System.Xml.Serialization.XmlAttributeAttribute()]
public string firstTxn { get; set; }
[System.Xml.Serialization.XmlAttributeAttribute()]
public string lastTxn { get; set; }
[System.Xml.Serialization.XmlAttributeAttribute()]
public string totalLifeTimeSale { get; set; }
[System.Xml.Serialization.XmlElementAttribute("department", typeof(List<department>), Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = )]
public List<department> department { get; set; }
}
怎么搞呢?在网上不停的找答案,最终都无解。但是没有放弃,答案也往往在快要放弃的时候出现
我尝试的修改了department的定义
修改前
[System.Xml.Serialization.XmlElementAttribute("department", typeof(List<department>), Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = )]
public List<department> department { get; set; }
修改后
[System.Xml.Serialization.XmlElementAttribute("department", typeof(department), Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = )]
public List<department> department { get; set; }
重新运行,奇迹出现
<?xml version="1.0"?>
<Response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" totalCount="" resultCode="ABC" resultMessage="测试">
<profile lastName="李" firstName="爽" dateOfBirth="XX0816" age="" gender="" address="浙江省 杭州富阳市 东州工业园区3号路1号杭州龙盛工贸有限公" email="htlslll@163.com" cellEmail="" socialMedia="" homePhone="" cellPhone="" contactabiltyMail="" contactabiltyEmail="" contactabiltyCellEmail="" contactabiltyHomePhone="" contactabiltyCellPhone="" contactabiltyText="" contactabiltySocialMedia="" vipLevel="" memberId="OC540C00016824" saAccount="" classa="小姐" homeStoreCode="OC54" />
<purchaseHistory>
<departmentPurchase totalLifeTimeSale="" totalTYAmount="" lastTxn="" totalTYUnitCnt="" firstTxn="">
<department categoryName="D08" tyAmount="" tyUnitCnt="" />
<department categoryName="D01" tyAmount="" tyUnitCnt="" />
<department categoryName="D02" tyAmount="" tyUnitCnt="" />
</departmentPurchase>
<ratePurchase totalLyAmount="" totalLyRate="" totalTyAmount="" totalTyRate="" totalLifeTimeAmount="" totalLifeTimeRate="">
<rate categoryName="Retail" lyAmount="" lyRate="" lyToDate="" tyAmount="" tyRate="" tyToDate="" lifeTimeAmount="" lifeTimeRate="" lyTyChange="" />
</ratePurchase>
<storeRatePurchase>
<storeRate />
</storeRatePurchase>
</purchaseHistory>
<vipStatus issueDate="" issueShop="OC54" ptsToUpgrade="" expiryDate="" upgradeShop="" ptsToRenew="" />
<comments comment="第一场雪" />
</Response>
问题解决。
原因就出在解析XML节点的
typeof(department) 与 typeof(List<department>)
记一次解析XML转对象的笔记的更多相关文章
- [C#]记一次解析XML转对象的笔记
项目中调用第三方API,返回格式是XML字符串,需要将XML反序列化为对象,格式如下: <?xml version="1.0"?> <Response xmlns ...
- JAXB解析XML为对象
JAXB支持注解将XML转化为对象,具体看一个简单的例子: <?xml version="1.0" encoding="utf-8"?> <A ...
- 解析xml的问题未解决
工作上需要解析xml,目前的逻辑是:解析xml到对象中,然后对象再插入数据库.但这存在内存溢出的风险. 今天做的另外一件事是将循环用到工作上,暂时还没有测试,是否能保证程序的重启.有待观察 ##### ...
- Java高级特性 第14节 解析XML文档(2) - SAX 技术
一.SAX解析XML文档 SAX的全称是Simple APIs for XML,也即XML简单应用程序接口.与DOM不同,SAX提供的访问模式是一种顺序模式,这是一种快速读写XML数据的方式.当使用S ...
- Android SAX解析XML
本篇讲解一下SAX解析XML这种方式,首先来看一下它的基本介绍: SAX是一种以事件驱动的XML API,由它定义的事件流可以指定从解析器传到专门的处理程序的代码的XML结构,简单的讲,它是种解析速度 ...
- Java xml 操作(Dom4J修改xml + xPath技术 + SAX解析 + XML约束)
1 XML基础 1)XML的作用 1.1 作为软件配置文件 1.2 作为小型的"数据库" 2)XML语法(由w3c组织规定的) 标签: 标签名不能以数字开头,中间不能有空格,区分大 ...
- 利用Java反射机制完成XML到对象的解析
对于一些小批量的数据,如果采用数据库来存取的话,未免有点大题小作,使用XML文件是个不错的方法,尤其是在一些Web应用中,经常需要缓存一部分数据,如果将这些数据形成XML文件,解析后放入一个Hasht ...
- webservice04#对象与xml转换-jaxb#Stax解析xml#新建修改xml
1,Student类 package com.yangw.xml; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement / ...
- 遍历文件 创建XML对象 方法 python解析XML文件 提取坐标计存入文件
XML文件??? xml即可扩展标记语言,它可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言. 里面的标签都是可以随心所欲的按照他的命名规则来定义的,文件名为roi.xm ...
随机推荐
- 安卓TCP通信版本2
PC做服务器,安卓做客户端. 安卓获取输入框的内容并发送,然后等待接收服务器的消息 服务器先行开启,接收到客户端的数据,然后回复消息. 实现了对线程类的封装,通过按钮启动线程发送并接收 服务器代码(j ...
- matab plot指令和低通滤波器的响应图
一.plot额外的四个属性模板使用 代码 % 提示 disp ('该功能练习plot额外四个属性功能'); %初始化快捷式数组 figure(); x=:pi/:*pi; y=exp(*sin(x)) ...
- PAT乙级 1065. 单身狗(25) by Python
1065. 单身狗(25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue "单身狗"是中文对 ...
- Python thread local
由于GIL的原因,笔者在日常开发中几乎没有用到python的多线程.如果需要并发,一般使用多进程,对于IO Bound这种情况,使用协程也是不错的注意.但是在python很多的网络库中,都支持多线程, ...
- 【转】IntelliJ IDEA2016.1 + maven 创建java web 项目
最近开始使用idea 来写java项目了,这个很流行,相比Eclipse方便了很多.功能多了,相对应的使用的复杂度也较高了,因为网上很多的使用和创建项目的简单教程,都是基于老版本的,每个新版本都有不一 ...
- 四色GDOI&GDOI2015滚粗记
好吧自己太弱写不了什么四色NOI只能学学别人写个四色GDOI了...首先自己还是太弱所以就被学校卡了个名额就进不了省队了QAQ.自己GDOI觉得考得不错可是NOIP毕竟少了人家5分根本追不上去好不QA ...
- Appuim源码剖析(Bootstrap)
Appuim源码剖析(Bootstrap) SkySeraph Jan. 26th 2017 Email:skyseraph00@163.com 更多精彩请直接访问SkySeraph个人站点:www. ...
- tornado学习 - TCPServer 实现聊天功能
最近学习tornado框架,其中有很多值得学习的模块,鉴于某位学长的建议,也决定好好看看tornado.tcpserver. 关于TCP协议详细介绍可查阅wiki. 对于TCP服务器,基本的操作tor ...
- xargs命令详解,xargs与管道的区别
为什么要用xargs,问题的来源 在工作中经常会接触到xargs命令,特别是在别人写的脚本里面也经常会遇到,但是却很容易与管道搞混淆,本篇会详细讲解到底什么是xargs命令,为什么要用xargs命令以 ...
- php封装+租房子练习题
第一个页面DBDA.class.php <?php class DBDA { public $host = "localhost"; public $uid = " ...