带有正则表达式json值的C#问题 [英] C# problem with regex json value
本文介绍了带有正则表达式json值的C#问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像下面这样的动态json对象,并试图用正则表达式解析它。
结果数组如{ID,1492,SourceID,AAA.A,Source,....}
{
ID: 1492,
SourceID: AAA.A,
来源: 1 ,
SourceID: 292,
子项: JKLM,
名称: KA PITAL YAT。 ,
ChildName: null ,
ListingDate: 20140428,
SeqNo: 10000000,
Average: 3092,3248,
SomeValue: null
}
我的模式未获得null并获得,
如何处理任何建议?
https://regex101.com/r/iFjq8w/2
我的尝试:
string pattern = @ (?< = \)([^ \ s]。*?)(?= \ );
MatchCollection matches = Regex.Matches(item.ToString(),pattern);
解决方案
如果你坚持,试试这个:string pattern = @(?< = \)([^ \,]。*?)(?= \)| null;
否则,探索将JSON解析为C#对象 [ ^ ]
这是Q& A中提到的常见问题。所以我写了一篇文章来回答这些类型的问题:在C#和amp中使用JSON ; VB [ ^ ]
I have a dynamic json objects like below and trying to parse it with regex.
result array like {ID,1492,SourceID,AAA.A,Source,....}
{
"ID" : "1492",
"SourceID" : "AAA.A",
"Source" : 1,
"SourceID" : "292",
"Child" : "JKLM",
"Name" : "KAPITAL YAT. ",
"ChildName" : null,
"ListingDate" : "20140428",
"SeqNo" : "10000000",
"Average" : "3092,3248",
"SomeValue" : null
}
my pattern does not get "null" and get ","
How can i handle this any suggestions?
https://regex101.com/r/iFjq8w/2
What I have tried:
string pattern = @"(?<=\")([^\s].*?)(?=\")";
MatchCollection matches = Regex.Matches(item.ToString(), pattern);
解决方案
If you insist, try this:string pattern = @"(?<=\"")([^\s,].*?)(?=\"")|null";
otherwise, explore Parse JSON into a C# Object[^]
This is a common question asked here in the Q&A. So I wrote an article to answer these types of questions: Working with JSON in C# & VB[^]
这篇关于带有正则表达式json值的C#问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文