2

Android Gson can not convert white space

I have this JSON:

{
                "_id": {
                    "$oid": "6108da994d809314a59829de"
                },
                "level": 1,
                "type": "smiling_points",
                "category": "pro",
                "sequence": [
                    {
                        "phrase": "1",
                        "isPhrase": false,
                        "showNumber": true
                    },
                    {
                        "phrase": "2",
                        "isPhrase": false,
                        "showNumber": false
                    },
                    {
                        "phrase": "( 19 + 21 ) / 4 = 10",
                        "isPhrase": false,
                        "showNumber": true
                    }
                ]
            }

and this model:

@Keep
data class SmilingPointsModel(
    val _id: OID,
    val level: Int,
    val type: String,
    val category: String,
    val time: Long,
    val sequence: ArrayList<SmilingPointsModelItem>
)

@Keep
data class SmilingPointsModelItem(
    val phrase: String,
    val isPhrase: Boolean
)

and try convert with this code:

val gson = GsonBuilder().disableHtmlEscaping().create()
model = gson.fromJson(data.game.toString(), SmilingPointsModel::class.java)

I have this error :

com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated object at line 1 column 197 path $.sequence[2].phrase

When I remove space from

( 19 + 21 ) / 4 = 10

its works but with Space I have above error. How I can fix this?

warsum
  • 29
  • 1

0 Answers0