C#에서이 스타일을 변환하고 싶습니다. 연락처를 추가하고 싶습니다. 어떻게해야합니까?C# JSON 데이터 배열
내 JSON은 :
이{
"contacts": [
{ "Id": "1",
"Name": "emre",
"Country": "istanbul"
},
{ "Id": "2",
"Name": "semih",
"Country": "siirt"
}
]
}
가 내 웹 서비스 :
이String resultJSON = "";
JavaScriptSerializer js = new JavaScriptSerializer();
try{
Context.Response.Clear();
Context.Response.ContentType = "application/json";
con.Open();
cmd = new SqlCommand("Select * from City", con);
reader = cmd.ExecuteReader();
dt = new DataTable();
con.Close();
JavaScriptSerializer serializer = new JavaScriptSerializer();
List<Dictionary<String, Object>> tableRows = new List<Dictionary<string, object>>();
Dictionary<String, Object> row;
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, dr[col].ToString());
}
tableRows.Add(row);
}
resultJSON = serializer.Serialize(tableRows).ToString();
}
catch (Exception ex)
{
resultJSON = ex.Message.ToString();
}
Context.Response.Write(resultJSON);
// return resultJSON;
}
@EmreAslan pls 대답. 비슷한 것이 도움이 될 것입니다. –
Ok 고맙습니다. –
@EmreAslan pls이 질문에 답변 한 경우 답변으로 표시합니다. –