从字符串中提取XML消息 [英] Extract XML message from a string

查看:93
本文介绍了从字符串中提取XML消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string msdg = "{"EventTimestamp":"2018-06-08 00:11:26,070", "Level":"INFO", "RouteId":"PubSubV2DistRoute",   
"ActivityTimestamp":"2018-06-07T23:13:50.363097Z", "SrcSys":"", "ShrActNr":"W0980X", "DtnCnyCd":"DE", "DtnFacMnm":"DESCK", "DtnSlicNr":"0445", "OrgCnyCd":"JP", "OrgFacMnm":"JPSHN", "OrgSlicNr":"1063", "IntSvcTypCd":"004", "ExtSvcTypCd":"012", "Message":"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>"}





我尝试了什么:



我想从以下字符串中提取该xml消息?



提前谢谢。



What I have tried:

I want to extract that xml message from the following string?

Thanks in advance.

推荐答案

首先,即使你设法编译它,代码也不会按原样编译 - 在字符串的开头添加 @ - 您只需要调用属性消息并获取所有内容需要什么太难了?



First of all, that code won't compile as it is, even if you manage to have it compiled — by adding a @ at the beginning of string — you would need to just call the property Message and get everything you need. What was too difficult in that?

dynamic obj = JsonConvert.DeserializeObject(msdg);

if(obj != null && obj.Message != null) {
    var xml = obj.Message;
    // use xml
}



我有一篇文章介绍了如何使用JSON.NET库在C#中处理JSON数据,请看一下那篇文章,从零到英雄在JSON与C# [ ^ ]。


这篇关于从字符串中提取XML消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆