Hello, I have this JSON String and need to get a value.
{
"data":{
"attributes":{
"email":"XXX@XXX.XXX",
"first_name":"XXX",
"full_name":"XXX",
"image_url":"https://c8.patreon.com/2/200/XXX",
"is_email_verified":true,
"last_name":"",
"thumb_url":"https://c8.patreon.com/2/200/XXX",
"url":"https://www.patreon.com/user?u=XXX",
"vanity":null
},
"id":"XXX",
"relationships":{
"memberships":{
"data":[
{
"id":"XXX",
"type":"member"
}
]
}
},
"type":"user"
},
"included":[
{
"attributes":{
"currently_entitled_amount_cents":100,
"last_charge_date":"2021-10-20T10:09:42.000+00:00",
"last_charge_status":"Paid",
"lifetime_support_cents":116,
"patron_status":"active_patron",
"pledge_relationship_start":"2021-10-20T10:09:40.763+00:00"
},
"id":"XXX",
"type":"member"
}
],
"links":{
"self":"https://www.patreon.com/api/oauth2/v2/user/XXX"
}
}
I need the value of currently_entitled_amount_cents
my try
using System.Collections;
using UnityEngine.Networking;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript2 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
// A correct website page.
StartCoroutine(GetRequest("https://www.example.com"));
// A non-existing page.
StartCoroutine(GetRequest("https://error.html"));
}
// Update is called once per frame
void Update()
{
}
IEnumerator GetRequest(string uri)
{
using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
{
// Request and wait for the desired page.
yield return webRequest.SendWebRequest();
string[] pages = uri.Split('/');
int page = pages.Length - 1;
switch (webRequest.result)
{
case UnityWebRequest.Result.ConnectionError:
case UnityWebRequest.Result.DataProcessingError:
Debug.LogError(pages[page] + ": Error: " + webRequest.error);
break;
case UnityWebRequest.Result.ProtocolError:
Debug.LogError(pages[page] + ": HTTP Error: " + webRequest.error);
break;
case UnityWebRequest.Result.Success:
Debug.Log(pages[page] + ":\nReceived: " + webRequest.downloadHandler.text);
JsonClass JsonClass = JsonUtility.FromJson<JsonClass>(webRequest.downloadHandler.text);
Debug.Log(JsonClass.included.attributes.currently_entitled_amount_cents);
break;
}
}
}
}
[System.Serializable]
public class JsonClass
{
public Included[] included;
}
[System.Serializable]
public class Included
{
public Attributes attributes;
}
[System.Serializable]
public class Attributes
{
public int currently_entitled_amount_cents;
}