Yeah that’s exactly what I did! and it seemed to like my output. It came out with this:
public class Customfield
{
public string type { get; set; }
public string value { get; set; }
public string name { get; set; }
public string shortname { get; set; }
}
public class Preference
{
public string name { get; set; }
public object value { get; set; }
}
public class RootObject
{
public int id { get; set; }
public string username { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
public string fullname { get; set; }
public string email { get; set; }
public string department { get; set; }
public int firstaccess { get; set; }
public int lastaccess { get; set; }
public string auth { get; set; }
public bool suspended { get; set; }
public bool confirmed { get; set; }
public string lang { get; set; }
public string theme { get; set; }
public string timezone { get; set; }
public int mailformat { get; set; }
public string description { get; set; }
public int descriptionformat { get; set; }
public string country { get; set; }
public string profileimageurlsmall { get; set; }
public string profileimageurl { get; set; }
public List<Customfield> customfields { get; set; }
public List<Preference> preferences { get; set; }
}
which I converted to this:
namespace ELearning
{
using System;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class Customfield
{
[SerializeField] private string type;
[SerializeField] private string value;
[SerializeField] private string name;
[SerializeField] private string shortname;
}
[Serializable]
public class Preference
{
[SerializeField] private string name;
[SerializeField] private object value;
}
[Serializable]
public class User
{
[SerializeField] private int id;
[SerializeField] private string username;
[SerializeField] private string firstname;
[SerializeField] private string lastname;
[SerializeField] private string fullname;
[SerializeField] private string email;
[SerializeField] private string department;
[SerializeField] private int firstaccess;
[SerializeField] private int lastaccess;
[SerializeField] private string auth;
[SerializeField] private bool suspended;
[SerializeField] private bool confirmed;
[SerializeField] private string lang;
[SerializeField] private string theme;
[SerializeField] private string timezone;
[SerializeField] private int mailformat;
[SerializeField] private string description;
[SerializeField] private int descriptionformat;
[SerializeField] private string country;
[SerializeField] private string profileimageurlsmall;
[SerializeField] private string profileimageurl;
[SerializeField] private List<Customfield> customfields;
[SerializeField] private List<Preference> preferences;
But it would throw out the: “JSON must represent an object type” all the time. So it accepts ‘object’ as a type and will automatically work with that, or cast to string?
This is the exact output of the json (though I’ve removed my login details for privacy:
[
{
"id": 6,
"username": "nigel",
"firstname": "Nigel",
"lastname": "",
"fullname": "Nigel",
"email": "nigel_.com",
"department": "",
"firstaccess": 1,
"lastaccess": 1,
"auth": "manual",
"suspended": false,
"confirmed": true,
"lang": "en",
"theme": "",
"timezone": "99",
"mailformat": 1,
"description": "",
"descriptionformat": 1,
"country": "GB",
"profileimageurlsmall": "http://www..co.uk/ecademy//image.php//core//u/f2",
"profileimageurl": "http://www..co.uk//theme/.php//core/1516033544/u/f1",
"customfields": [
{
"type": "checkbox",
"value": "0",
"name": "Food Allergies",
"shortname": "FoodAllergies"
}
],
"preferences": [
{
"name": "auth_manual_passwordupdatetime",
"value": "1511800938"
},
{
"name": "block_myoverview_last_tab",
"value": "courses"
},
{
"name": "email_bounce_count",
"value": "1"
},
{
"name": "email_send_count",
"value": "5"
},
{
"name": "login_failed_count_since_success",
"value": "4"
},
{
"name": "theme_adaptable_full",
"value": "fullin"
},
{
"name": "theme_adaptable_zoom",
"value": "nozoom"
},
{
"name": "_lastloaded",
"value": 1518708035
}
]
}
]
Lastly you say json.net will get that working. Do you know whether the built in Unity JsonUtility covers it?