PS: Mainly a configuration file and a conversion function
Config file app. Config before you 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 "/& Gt <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= "BasePenTy PE "/> <add key=" body.port5 "value=" Basepentypeid "/> <add key=" body.port6 "value=" MID "/> <add ke Y= "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 "/> <a DD key= "body.port12" value= "EquipmentID2"/> </appSettings></configuration>
Conversion functions:
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) + "}"; }
It took 5 hours to study because it wasn't a computer major.
Isn't it very easy?
(*^__^*) hehe
C # Converts an MSMQ message into JSON format