WPFアプリケーションでJson.netを使用しようとしています。接続しているWebサーバーから、次のような文字列を取得します。
[{"id": "11"、 "title": "デフォルト"、 "nclient": "3"}、{"id": "18"、 "title": "GrupoPorreiro"、 "nclient": "0 "}]
そしてそれを逆シリアル化するために使用しているコードはこれです。
public void preencheCampos()
{
try
{
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("URL");
//request.Method = "POST";
request.ContentType = "application/json";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11";
request.CookieContainer = ApplicationState.GetValue<CookieContainer>("cookie");
WebResponse response = request.GetResponse();
Stream data = response.GetResponseStream();
String html = String.Empty;
request.CookieContainer = ApplicationState.GetValue<CookieContainer>("cookie");
using (StreamReader sr = new StreamReader(data))
{
html = sr.ReadToEnd();
}
StringBuilder sb = new StringBuilder();
List<string> entities = (List<string>)JsonConvert.DeserializeObject(html, typeof(List<string>));
foreach (string items in entities)
{
sb.Append(items);
}
//...
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
しかし、JsonConvert.DeserializeObjectの部分に到達すると、次のような例外が発生します。
「文字列の読み取りエラー。予期しないトークン:StartObject。パス'[0]'、1行目、2番目の位置。」