Deserializing JSON with JSONUltility: Lists?

How exactly can I get a the latitude and longitude values from this JSON?

{"iss_position": {"longitude": "99.3445", "latitude": "-50.7022"}, "message": "success", "timestamp": 1571583963}

I’ve attached the code I am using to fetch and parse the JSON. It can display the message and timestamp values from the JSON just fine, but when doing that I do get this error (despite it working):

Unexpected node type.
UnityEngine.JsonUtility:FromJson(String)
<OnResponse>c__Iterator0:MoveNext() (at Assets/API.cs:17)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

Any method I have tried of displaying a string in the iss_position list has failed. In addition, when I use Count to display the length of the list, it returns zero, so I assume I’m doing something very wrong. If anyone could point me in the right direction, I’d really appreciate it. Thanks!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class API : MonoBehaviour {
    private const string url = "http://api.open-notify.org/iss-now.json";
    // Use this for initialization
    void Start () {
        WWW request = new WWW (url);
        StartCoroutine (OnResponse (request));
    }

    private IEnumerator OnResponse(WWW req) {
        yield return req;
        ISSData data = JsonUtility.FromJson<ISSData>(req.text);
        Debug.Log (data.message);
    }
}

[System.Serializable]
public class ISSData
{
    public string message;
    public int timestamp;
    public List<Position> iss_position;
}

[System.Serializable]
public class Position
{
    public string latitude;
    public string longitude;
}

The long and lat aren’t a list, they are two floats which you would place in a class. This should do it for you;

using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;

public class IssData : MonoBehaviour
{
    public IssInfo Info;

    private IEnumerator Start()
    {
        var www = new UnityWebRequest("http://api.open-notify.org/iss-now.json")
        {
            downloadHandler = new DownloadHandlerBuffer()
        };

        yield return www.SendWebRequest();

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.Log("Error Loading ISS Data");
            yield break;
        }

       Info = JsonUtility.FromJson<IssInfo>(www.downloadHandler.text);
    }
}

[Serializable]
public class IssInfo
{
    public IssPosition iss_position;
    public string message;
    public int timestamp;
}

[Serializable]
public class IssPosition
{
    public float longitude;
    public float latitude;
}

Thanks so much! Everything works as intended now and I understand what I was doing wrong. I really appreciate your help!

Still that error shouldn’t happen. The field should just be ignored if the field type doesn’t match like “FromJson” does for other situations.
Please vote this issue here:

This error can happen if for example you get a malformed json and you want to handle the exception gracefully in your code by catching it. But this error is not catch-able.