Click here to Skip to main content
14,878,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a C# string which was pulled from a TCP/IP stream. I need to convert this string to a JSON Object to transport over HTTP.

The string will look something like:

XXX:YYYY:PARAM1=abcd, PARAM2=defg

with their being any number of parameters following the second colon.

Do I have to parse this string out into an object to serialize it or is there another way?

I am working with Visual Studio 2010 and have the JSON.NET framework.
Posted
Comments
BobJanova 2-Nov-11 12:43pm
   
Is what's after the colons valid JSON (with a small bit of manipulation i.e. putting a { ... } around it)? If so, use JSON.net. Otherwise you're pretty much going to have to parse it, if it's a custom format, and reformat as JSON.

1 solution

One simple approach would be to parse the string, create an anonymous object from that (using LINQ is one way), and then create a JSON object via serialization.
   

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