Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello there's..
I want to concatenate two json string.
first string contains data tables records details and other string contains Count value.
I get that values In data set such that.

dataset ds.Tables[0]= //table records
ds.tables[1]=// singale integer value (e.g. TotalCount=12)

I convert ds in json but it return json string like.
{"contactList":[{"Name":"Abhijit Goswami","email":"abhijitda@facebook.com","contactNo":"9158417355","gender":"Male"},{"Name":"Abhijit Goswami","email":"abhijitda@facebook.com","contactNo":"9158417355","gender":"Male"},{"Name":"Abhijit Goswami","email":"abhijitda@facebook.com","contactNo":"9158417355","gender":"Male"}],"totalCount":[{"Total":192}]}


In above string I don't want to totalCount value in array.
I just want to "totalCount:192" after the contact list array.

{"contactList":[{"Name":"Abhijit Goswami","email":"abhijitda@facebook.com","contactNo":"9158417355","gender":"Male"},{"Name":"Abhijit Goswami","email":"abhijitda@facebook.com","contactNo":"9158417355","gender":"Male"}],"totalCount":192}


What I have tried:

currently my code for converting DataSet to JSON string as bellow

ds.Tables[0].TableName = "contactList";
        ds.Tables[1].TableName = "totalCount";             
        json = JsonConvert.SerializeObject(ds, Formatting.None);
Posted
Updated 26-Jan-17 2:26am
v2
Comments
[no name] 26-Jan-17 1:01am    
https://www.merriam-webster.com/dictionary/incontinent
Vikas Hire 26-Jan-17 1:07am    
typing mistake

1 solution

Try something like this:
C#
json = JsonConvert.SerializeObject(new 
{
    contactList = ds.Tables[0],
    totalCount = ds.Tables[1].Rows.Cast<DataRow>().Select(r => r[0]).FirstOrDefault()
}, Formatting.None);
 
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