Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: JSON
Hi
I have created json string using string builder and now i want to convert it to json using json.net without the use of classes.I have given example below.
 
Thanks in advance.
 

SqlCommand cmd = new SqlCommand("SELECT tcjc_ID, tcjc_JobCode, tcjc_Name, tcjc_JobDesc1 + tcjc_JobDesc2 + tcjc_JobDesc3, tco_Company_Name, tsi_Site_Name FROM tbl_CreateJobCosting LEFT JOIN tbl_Companies ON tcjc_CompanyId = tco_CompanyId LEFT JOIN tbl_Sites ON tcjc_SiteId = tsi_SiteID WHERE tcjc_ID = " + jobId, con);
sb.Append("{ \"jobId\":\"");
sb.Append(jobId);
sb.Append("\",");
try
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
sb.Append("\"jobcode\":\"");
sb.Append(reader.GetInt32(1));
sb.Append("\", \"name\":\"");
sb.Append(reader.GetString(2));
sb.Append("\", \"desc\":\"");
sb.Append(reader.GetString(3));
sb.Append("\", \"company\":\"");
sb.Append(reader.GetString(4));
sb.Append("\", \"site\":\"");
sb.Append(reader.GetString(5));
}
Posted 7-Apr-13 22:17pm
Comments
Anurag Sinha V at 8-Apr-13 3:36am
   
So, where are you stuck??
Prasad Khandekar at 8-Apr-13 15:41pm
   
Hello Neeraj,
 
i want to convert it to json using json.net without the use of classes, is like saying Unless I learn to swim I won't get into the water. Json.Net is a library which allows you to work with JSON data structure and it also provides de/serialization services for converting object into JSON format and vice versa.
 
Any way without using the classes you have created the JSON string. So where is the problem?
NeerajRathi at 9-Apr-13 0:53am
   
Hi Prasad
Thanks for suggestion.I have solve the problem using Json.Net.
 
Thanks
Neeraj

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

  Print Answers RSS
0 Marcin Kozub 265
1 Richard MacCutchan 239
2 OriginalGriff 208
3 Sergey Alexandrovich Kryukov 185
4 Praneet Nadkar 167
0 OriginalGriff 7,913
1 Sergey Alexandrovich Kryukov 7,232
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,865


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 8 Apr 2013
Copyright © CodeProject, 1999-2014
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