HI,문자열 전체 가치를 내가 여기에 도움을 절실히 필요 해요
나는 웹 요청을 만드는 중이을 전달하고 Response.ContentLenth=2246
와 JSON 문자열을 받고하지만 난 문자열을 구문 분석 할 때 100 만 몇 준다 문자, 나는 964보다 작은 값을 얻는다는 것을 추적했다. 문자열 길이는 여전히 2246이지만 나머지 값은 단지 (\0)
null
문자이다. 그것 또한 다음 줄
FacebookFeed feed = sr.Deserialize<FacebookFeed>(data);
응답 스트림이 964 개 문자보다 적은 문자가 포함 된 경우 그것은 잘 작동에 오류 Unterminated string passed in. (2246):
을 제공합니다.
다음은 마지막 줄에서 발생한 전체 코드 오류에서 추출한 것입니다. 주어진
System.Web.Script.Serialization.JavaScriptSerializer sr = new System.Web.Script.Serialization.JavaScriptSerializer();
System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(@"https://graph.facebook.com/100000570310973_181080451920964");
req.Method = "GET";
System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
byte[] resp = new byte[(int)res.ContentLength];
res.GetResponseStream().Read(resp, 0, (int)res.ContentLength);
string data = Encoding.UTF8.GetString(resp);
FacebookFeed feed = sr.Deserialize<FacebookFeed>(data);
오류가
Unterminated string passed in. (2246): {"id":"100000570310973_1810804519209........ (with rest of data in the string data including null chars)
내 코드에 사용되는 클래스의 형태입니다 다음과 같다 :
public class FacebookFeed
{
public string id { get; set; }
public NameIdPair from { get; set; }
public NameIdPair to { get; set; }
public string message { get; set; }
public Uri link{get;set;}
public string name{get; set;}
public string caption { get; set; }
public Uri icon { get; set; }
public NameLinkPair[] actions { get; set; }
public string type { get; set; }
public NameIdPair application { get; set; } //Mentioned in Graph API as attribution
public DateTime created_time { get; set; }
public DateTime updated_time { get; set; }
public FacebookPostLikes likes { get; set; }
}
public class NameIdPair
{
public string name { get; set; }
public string id { get; set; }
}
public class NameLinkPair
{
public string name { get; set; }
public Uri link{get; set;}
}
public class FacebookPostLikes
{
public NameIdPair[] data { get; set; }
public int count { get; set; }
}
오 !! 나는 그것을 생각하지 않았다. 고맙습니다. –