package com.xty.network.utils

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.xty.network.model.SelectedAnswerBean
import com.xty.network.model.TongueQuestionBean

object JsonParser {
    fun parseTongueQuestionBean(jsonString: String): List<TongueQuestionBean> {
        val gson = Gson()
        val questionListType = object : TypeToken<List<TongueQuestionBean>>() {}.type
        val questions = gson.fromJson<List<TongueQuestionBean>>(jsonString, questionListType)

        // 对每个问题的 answerOptions 进行逗号分隔并转换为列表
        questions.forEach { question ->
            val answerOptionsArray = question.answerOptions.split(",") // 将字符串分割成数组
            question.answerOptionsArray = answerOptionsArray // 将数组保存到问题对象中
        }
        return questions
    }

    fun parseTongueQuestionAnswerBean(jsonString: String): List<SelectedAnswerBean> {
        val gson = Gson()
        val questionListType = object : TypeToken<List<SelectedAnswerBean>>() {}.type
        val questions = gson.fromJson<List<SelectedAnswerBean>>(jsonString, questionListType)
        return questions
    }
}