Newtonsoft. Json .JsonSerializationException: Невозможно десериализовать массив Current JSON (например, [1,2,3]) в тип 'Quiz', firebase - PullRequest
0 голосов
/ 08 января 2020

я пытаюсь получить данные с базы огня, и у меня возникла проблема с json

это ошибка

ошибка 1

Newtonsoft. Json .JsonSerializationException: Невозможно десериализовать текущий массив JSON (например, [1,2,3]) в тип 'Викторина', потому что тип требует JSON объекта (например, {"name": "value"}) для правильной десериализации.

У меня есть этот класс Викторина

[System.Serializable]
public class Quiz 
{
    public string questionIs;
    public string theGoodAnswer;
    [Header("Bad answers")]
    public List<string> AnswerList;

    public Quiz()
    {

    }
    public Quiz(List<string> AnswerList, string questionIs, string theGoodAnswer)
    {
        this.AnswerList = AnswerList;
        this.questionIs = questionIs;
        this.theGoodAnswer = theGoodAnswer;

    }
}

и вот как я пытаюсь получить данные из firebase

 public void OpenPanel()
    {
FirebaseDatabase.DefaultInstance
   .GetReference("Position10")
   .ValueChanged += HandleValueChanged;
  }


  void HandleValueChanged(object sender, ValueChangedEventArgs args)
    {
        if (args.DatabaseError != null)
        {
            Debug.LogError(args.DatabaseError.Message);
            return;
        }
        Debug.Log(args.Snapshot.Child("AnswerList").Value);

        theQuiz.questionIs = args.Snapshot.Child("questionIs").Value.ToString();
        Debug.Log(theQuiz.questionIs);
        theQuiz.theGoodAnswer = args.Snapshot.Child("theGoodAnswer").Value.ToString();
        Debug.Log(theQuiz.theGoodAnswer);

        foreach (DataSnapshot user in args.Snapshot.Children)
        {

            Quiz client = JsonConvert.DeserializeObject<Quiz>(user.GetRawJsonValue());

            foreach (var item in client.AnswerList)
            {
                Debug.Log(client);


            }
        }

    }

, и я получаю эту ошибку, и я не могу десериализовать текущий массив JSON (например, [1,2,3] ) в тип. Что не так в этом коде, пожалуйста?

this is an example of the data that I saw in the firebase

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...