Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Need Help with JSON Dot Net Plugin

Discussion in 'Scripting' started by WanAmir, Mar 23, 2022.

  1. WanAmir

    WanAmir

    Joined:
    Jul 17, 2018
    Posts:
    27
    Hi.
    I'm trying to read json data from web page using UnityWebRequest.
    So this is my code:
    Screenshot_3.png

    This is PlayerData class:
    Screenshot_6.png

    On line 63 i got the content in page but i got an error on line 66. It cannot put the content on the PlayerDatas. Im using JsonDotNet plugin from asset store.

    This is the content:
    Screenshot_4.png

    This is the error:
    Screenshot_5.png

    I really appreciate any help. Thank you in advance :)
     
  2. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,531
    Your json data represents an object with only a single field called PlayerDatas. You try to deserialize it as a List of PlayerData. So you need a class that represents your actual json data. Namely something like this:

    Code (CSharp):
    1. [System.Serializable]
    2. public class PlayerInfo
    3. {
    4.     public List<PlayerData> PlayerDatas;
    5. }
    Of course when deserializing you would need to use this class.
     
    WanAmir likes this.
  3. WanAmir

    WanAmir

    Joined:
    Jul 17, 2018
    Posts:
    27
    Funny enough. i already have a GameData class that look like this:

    Code (CSharp):
    1. [System.Serializable]
    2. public class GameData
    3. {
    4.     public List<PlayerData> PlayerDatas = new List<PlayerData>();
    5. }
    but i never use it. Now i know their purpose. Thank you so much, I really appreciate it
     
    Bunny83 likes this.