zauber3r
zauber3r

Reputation: 95

JSONArray to List with GSON

I have an array like this:

[{"poolkost":"IWXI"},{"poolkost":"ILXI"},{"poolkost":"VGXI"}]

and want to put it in a List using the tutorial How to convert JSONArray to List with Gson?

My Code:

    String jsonStr = DBFunction.GetBoxer(GlobalClass.DIR);
    Gson gson = new Gson();
    Type listType = new TypeToken<List<String>>(){}.getType(); //ERROR 1
    List<String> PoolList = gson.fromJson(jsonStr, listType);  //ERROR 2

I get 2 errors:

Error 1:

Type mismatch: cannot convert from java.lang.reflect.Type to android.renderscript.Type

Error 2:

The method fromJson(String, Class<T>) in the type Gson is not applicable for the arguments (String, Type)

I cannot fix the first Error, either the second...

Upvotes: 1

Views: 630

Answers (1)

durron597
durron597

Reputation: 32323

Check your imports.

Remove this:

import android.renderscript.Type;

Add this:

import java.lang.reflect.Type;

This should fix both problems.

Upvotes: 2

Related Questions