標籤:sage sep value datetime 嘻嘻 run html ati man
PS:主要就是一個設定檔和一個轉換函式
設定檔app.config 之前要ADD reference --> system.configuration & using.system.configuration
<?xml version="1.0" encoding="utf-8" ?><configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <appSettings> <add key="Lable.Port1" value="MessageID"/> <add key="Lable.Port2" value="SendingBaseTag"/> <add key="Lable.Port3" value="SendingMachineName"/> <add key="Lable.Port4" value="MessageQueuePathName"/> <add key="Lable.Port5" value="CustomField1"/> <add key="Lable.Port6" value="CustomField2"/> <add key="Body.Port1" value="DataMode"/> <add key="Body.Port2" value="DataModeID"/> <add key="Body.Port3" value="ExperimentID"/> <add key="Body.Port4" value="BasePenType"/> <add key="Body.Port5" value="BasePenTypeID"/> <add key="Body.Port6" value="MID"/> <add key="Body.Port7" value="StationTag"/> <add key="Body.Port8" value="DateTime"/> <add key="Body.Port9" value="Path1"/> <add key="Body.Port10" value="EquipmentID1"/> <add key="Body.Port11" value="Path2"/> <add key="Body.Port12" value="EquipmentID2"/> </appSettings></configuration>
轉換函式:
private string ConvertToJSON(string label, string body) { //TODO: convert to json string[] Lablelist = label.Split(‘|‘); string[] Bodylist = body.Split(‘|‘); string[] LableName = new string[6]; string[] BodyName = new string[12]; string JsonStr = "{\""; for(int j=1;j<7;j++) { JsonStr = JsonStr + ConfigurationManager.AppSettings["Lable.Port" + j.ToString()] +"\":\""+Lablelist[j-1] + "\",\""; } for (int i = 1; i < 13;i++ ) { JsonStr = JsonStr + ConfigurationManager.AppSettings["Body.Port" + i.ToString()] + "\":\"" + Bodylist[i - 1] + "\",\""; } JsonStr = JsonStr.Remove(JsonStr.Length - 2, 2)+"}"; }
由於不是電腦專業,研究了下 花了5個小時
是不是非常easy?
(*^__^*) 嘻嘻
C# 將MSMQ訊息轉換成Json格式