Click here to Skip to main content
15,902,918 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dynamic json objects like below and trying to parse it with regex.
result array like {ID,1492,SourceID,AAA.A,Source,....}
JavaScript
{
  "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:

C#
 string pattern = @"(?<=\")([^\s].*?)(?=\")";
MatchCollection matches = Regex.Matches(item.ToString(), pattern);
Posted
Updated 1-Nov-17 5:11am
v2
Comments
Mehdi Gholam 1-Nov-17 9:34am    
Why don't you use the json parser?

If you insist, try this:
string pattern = @"(?<=\"")([^\s,].*?)(?=\"")|null";

otherwise, explore Parse JSON into a C# Object[^]
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 1-Nov-17 23:33pm    
5
Peter Leow 2-Nov-17 3:27am    
Thank you, Karthik.
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900