Click here to Skip to main content
11,490,543 members (33,839 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# JSON
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:


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 2-Nov-11 6:44am
BobJanova at 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 Otherwise you're pretty much going to have to parse it, if it's a custom format, and reformat as JSON.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 520
1 Andy Lanng 233
2 Sascha Lefèvre 210
3 OriginalGriff 188
4 Maciej Los 160
0 Sergey Alexandrovich Kryukov 9,713
1 OriginalGriff 8,475
2 Sascha Lefèvre 3,544
3 Maciej Los 3,106
4 Richard Deeming 2,370

Advertise | Privacy | Mobile
Web02 | 2.8.150520.1 | Last Updated 2 Nov 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100