I need assistance converting my data into the correct JSON format. The current structure of my data is as follows:
[
"{
id:001,
name:akhilesh,
}",
"{
id:002,
name:Ram,
}"
]
My goal is to transform the above data into valid JSON:
[
{
"id":"001",
"name":"akhilesh"
},
{
"id":"002",
"name":"Ram"
}
]
I've attempted several methods such as JSON.serialize
, JSON.parse
, and eval
, but have not found success with any of them.
If anyone could provide guidance on this issue, it would be much appreciated.
The data response from the server side is as follows:
{
"d": [
"{id:413,title:ranjan,start:413,end:413}",
"{id:414,title:raja,start:414,end:414}",
"{id:415,title:raja g,start:415,end:415}",
...
"{id:440,title:yash,start:440,end:440}"
]
}
Server-Side Code:
[System.Web.Services.WebMethod]
public static List<string> getData()
{
List<string> data = new List<string>();
using (SqlConnection con = new SqlConnection("Data Source=ACME-PC\\SQL;Integrated Security=true;Initial Catalog=ClinicApplication"))
{
SqlCommand cmd = new SqlCommand("select DISTINCT Patient_ID,First_Name,fromtime,totime,Date from tbl_AddPatientInfo", con);
{
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
string id = "{" +
"\"id:\"" + dr["Patient_ID"].ToString() + "," +
"title:" + dr["First_Name"].ToString() + "," +
"start:" + dr["Patient_ID"].ToString() + "," +
"end:" + dr["Patient_ID"].ToString() +
"}";
string ids = id.Replace(@"""", "");
data.Add(ids);
}
return data;
}
}
}