Rest Web API 응답을 읽으려고합니다. 데이터를 구문 분석하는 동안 오류가 발생합니다.
응답 내용 유형 : application / json; charset = utf-8
응답 : { "access_token": "ot-a4943ac25cf94df3adacd11c71b8ea01", "token_type": "Bearer", "scope": [ "READ_USER_PROFILE", "WRITE_CONVERSATIONS", "READ_CONVERSATIONS"]}
DTO :
public class ResponseData
{
public string AccessToken { get; set; }
public string TokenType { get; set; }
public string Scope { get; set; }
}
public class Scope
{
public string[] RequestScope { get; set; }
}
암호:
using (HttpContent rescontent = response.Result.Content)
{
// ... Read the string.
Task<string> result = rescontent.ReadAsStringAsync();
// res = result.Result;
var responseData = JsonConvert.DeserializeObject<ResponseData>(result.Result);
Console.WriteLine("Response: {0}", responseData.AccessToken);
}
오류 : Newtonsoft.Json.JsonReaderException : '값을 구문 분석하는 동안 예기치 않은 문자가 발생했습니다 : [. 경로 '범위', 줄 1, 위치 85. '
프로그래밍 언어 : C #
이 문제를 해결하는 방법을 알려주십시오. 응답에서 액세스 토큰 매개 변수를 읽고 싶습니다.
당신은 누락 배열 로 표시 [
하고 ]
에서 JSON을
{
"access_token":"ot-a4943ac25cf94df3adacd11c71b8ea01",
"token_type":"Bearer",
"scope":[ // this is an array
"READ_USER_PROFILE",
"WRITE_CONVERSATIONS",
"READ_CONVERSATIONS"
]
}
수업을 수정해야합니다.
public List<string> Scope { get; set; }
또는
public string[] Scope { get; set; }
편집하다
다른 오류도있을 수 있으므로이를 변경해야 할 수 있습니다.
public string Access_Token { get; set; }
public string Token_Type { get; set; }
또는
[JsonProperty("access_token")]
public string Access_Token { get; set; }
[JsonProperty("token_type")]
public string TokenType { get; set; }
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다