-2
引用數組和記錄序列化時我與Newtonsoft的Json.net對象,我得到:如何序列化對象沒有json.net
{"status":"1",
"message":"test",
"records":"[{\"id\":\"1\", \"name\":\"file1\"},
{\"id\":\"2\", \"name\":\"file2\"},
{\"id\":\"3\", \"name\":\"file3\"}]" // I want to get rid of the extra quotes for the array
}
我想有:
{"status":"1",
"message":"test",
"records":[{"id":"1", "name":"file1"},
{"id":"2", "name":"file2"},
{"id":"3", "name":"file3"}] // NOTE: this is an Array of records
}
這是簡化的代碼我使用來序列:
QHttpResponse tempResponse = new QHttpResponse() { StatusCode = (int)HttpStatusCode.OK, Message = "File found." };
JObject jo = JObject.FromObject(tempResponse);
jo.Add("records",JsonConvert.SerializeObject(jo));
這是QHttpResponse類:
public class QHttpResponse
{
#region Feilds
/// <summary>
/// Status code of the http response (e.g.:400 = bad request.)
/// </summary>
[JsonProperty("status_code")]
public int StatusCode { get; set; }
/// <summary>
/// Message (Content) of the response.
/// </summary>
[JsonProperty("message")]
public string Message { get; set; }
#endregion
}
結帳這[JSONLint網站](http://jsonlint.com/)在這裏你驗證有效或無效的JSON蜇 – MethodMan
它看起來像你有一個小''jo'添加到'jo'的錯字 – ohmusama
@ohmusama:是的,我也掛了... –