0
荫使用Newtonsoft.Json格式化的Json
对于这个我下面的代码,
[WebMethod]
public static string GetData()
{
string msg = string.Empty;
string json;
using (MySqlConnection con = new MySqlConnection("Server=localhost;Database=working_sample;uid=root;[email protected];pooling=false;"))
{
using (MySqlCommand cmd = new MySqlCommand("select * from json_example_table where subject='Swe'", con))
{
con.Open();
cmd.ExecuteScalar();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
json = JsonConvert.SerializeObject(ds.Tables[0]);
// Using this I am getting single letter as output
// IN ASPX Code is as below.....
success: function (data) {
var objdata = $.parseJSON(data.d);
var obj = data.d;
$('#txtname').val(obj[0]); // This is giving "[" as output
//var settings = new JsonSerializerSettings { Formatting = Formatting.Indented };
//string jsonn = JsonConvert.SerializeObject(ds, Formatting.None, settings);
con.Close();
}
}
return json;
}
什么我现在做的就是正确的输出... 我试图与格式,但它给错误作为
错误
ambiguous ref btwn System.Xml.Formatting and System.Json.Formatting
任何帮助请
但namesapce名Json的系统中存在多年平均值..命名空间,这是错误 – Pink
@Pink,更新了我的答案 –
Newtonsoft.Json.Formatting.JsonSerializerSettings不包含格式定义 – Pink