How to read a JSON response in Unity?

raja

I am new to Unity and I have been trying read the JSON response from my RESTful API using C#. Here's what I've tried with LitJson:

JsonData jsonvale = JsonMapper.ToObject(www.text);

string parsejson;
parsejson = jsonvale["myapiresult"].ToString();

My JSON response is {"myapiresult":"successfull"}

For whatever reason, it doesn't work currently. I don't know how to fix it.

I also found a paid plugin for JSON.NET but I'm not sure if it will solve my problem.

cbr

You don't need to buy any paid plugins to use JSON.NET here. You can either create a class that models the response or deserialize to a dynamic object.

Example of the former:

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
}

...and the latter:

using Newtonsoft.Json;
// ...
void Main()
{
    string responseJson = "{\"myapiresult\":\"successfull\"}";
    dynamic response = JsonConvert.DeserializeObject(responseJson);
    Console.WriteLine(response.myapiresult.ToString());
    // Output: successfull
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to read JSON response?

From Dev

How to read MediaWiki API JSON response

From Dev

How to read the Json Response in android activity.

From Dev

Read xml response in unity Android

From Dev

json response, read data

From Dev

How to read JSON error response from $http if responseType is arraybuffer

From Dev

RestAssured - How to read an array element from the json response

From Dev

How to read a JSON response using HttpClient in vb.net

From Dev

How to read json response from node js server?

From Dev

How to read a json response from a akka-http response entity using json4s

From Dev

Read data from json response

From Dev

How to read the response from a NewSingleHostReverseProxy

From Dev

How to read response headers in angularjs?

From Dev

How to read AJAX response variable?

From Dev

How to read response headers with $resource?

From Dev

How to customize json response?

From Dev

How to create json response

From Dev

How to parse a JSON response

From Dev

How to use this JSON response?

From Dev

Read JSON response object in php/js

From Dev

Read var_export output of JSON response

From Dev

Send and receive Json, cant read the response

From Dev

Read Response From Json Post Call Swift

From Dev

Cannot read big json response from Ruby

From Dev

Read JSON response object in php/js

From Dev

q-io: how to read response.body JSON object using Promises?

From Dev

How to read RAW JSON in Angular JS from HTTP get method, when response type is arraybuffer?

From Dev

How to read JSON response while using $.post to send & receive data to PHP alongwith done & fail functions

From Dev

How to read JSON response containing an array of objects of a user-defined class?

Related Related

HotTag

Archive