저는 Unity를 처음 사용하고 C #을 사용하여 RESTful API에서 JSON 응답을 읽으려고했습니다. LitJson으로 시도한 내용은 다음과 같습니다.
JsonData jsonvale = JsonMapper.ToObject(www.text);
string parsejson;
parsejson = jsonvale["myapiresult"].ToString();
내 JSON 응답은 {"myapiresult":"successfull"}
어떤 이유로 든 현재 작동하지 않습니다. 나는 그것을 고치는 방법을 모른다.
또한 JSON.NET 용 유료 플러그인을 찾았지만 문제를 해결할 수 있을지 모르겠습니다.
여기에서 JSON.NET 을 사용하기 위해 유료 플러그인을 구입할 필요가 없습니다 . 응답을 모델링하는 클래스를 만들거나 동적 개체로 역 직렬화 할 수 있습니다.
전자의 예 :
using Newtonsoft.Json;
// ...
class Response
{
[JsonProperty(PropertyName = "myapiresult")]
public string ApiResult { get; set; }
}
void Main()
{
string responseJson = "{\"myapiresult\":\"successfull\"}";
Response response = JsonConvert.DeserializeObject<Response>(responseJson);
Console.WriteLine(response.ApiResult);
// Output: successfull
}
... 후자 :
using Newtonsoft.Json;
// ...
void Main()
{
string responseJson = "{\"myapiresult\":\"successfull\"}";
dynamic response = JsonConvert.DeserializeObject(responseJson);
Console.WriteLine(response.myapiresult.ToString());
// Output: successfull
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다