Click here to Skip to main content
15,888,100 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to split the string at "Source_Address" not on "Parameter_Source_Address" how do i match exact string while parsing.


my input string is

[{"Name":"Engine Oil Level","Parameter_Source_Address":"","Value":"0"},{"Name":"Engine Oil Pressure (High Resolution\/Extended Range)","Parameter_Source_Address":"","Value":"3.5"},{"Name":"Engine Pre-Filter Oil Pressure (High Resolution\/Extended Range)","Parameter_Source_Address":"","Value":"4"},{"Name":"Engine Oil Filter Differential Pressure (Extended Range)","Parameter_Source_Address":"","Value":"0"}],"Snapshot_DateTimestamp":"2016-10-13T09:28:38.000Z"}],"Source_Address":"0","Telematics_Box_Hardware_Variant":"0300","Telematics_Box_ID":"0300","Telematics_Box_Software_Version":"0300","Telematics_Partner_Message_ID":"0300_212_1661010233_20161013092805480_1.zip","Telematics_Partner_Name":"KomtraxPlus","VIN":""}

output should be:

string[] A=

[{"Name":"Engine Oil Level","Parameter_Source_Address":"","Value":"0"},{"Name":"Engine Oil Pressure (High Resolution\/Extended Range)","Parameter_Source_Address":"","Value":"3.5"},{"Name":"Engine Pre-Filter Oil Pressure (High Resolution\/Extended Range)","Parameter_Source_Address":"","Value":"4"},{"Name":"Engine Oil Filter Differential Pressure (Extended Range)","Parameter_Source_Address":"","Value":"0"}],"Snapshot_DateTimestamp":"2016-10-13T09:28:38.000Z"}]

string[] B={"Source_Address":"0","Telematics_Box_Hardware_Variant":"0300","Telematics_Box_ID":"0300","Telematics_Box_Software_Version":"0300","Telematics_Partner_Message_ID":"0300_212_1661010233_20161013092805480_1.zip","Telematics_Partner_Name":"KomtraxPlus","VIN":""}


Thanks.

What I have tried:

string[] delimiter2 = new string[] {"Source_Address"};

string[] array4 = array3.Split(delimiter2,StringSplitOptions.RemoveEmptyEntries);


foreach (string entry1 in array4)
{
array5 = entry1;

}
It split string on "Parameter_Source_Address"

i am getting following output:

[{"Name":"Engine Oil Level","Parameter_
":"","Value":"0"},{"Name":"Engine Oil Pressure (High Resolution\/Extended Range)","Parameter_
Posted
Updated 13-Dec-16 12:45pm
Comments
[no name] 13-Dec-16 18:42pm    
Use a JSON parser to parse JSON.

1 solution

This looks like JSON data. Use a JSON parser.
See: JSON Serialization and Deserialization in ASP.NET[^]
 
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