Domanda

Mi chiedevo, dato il seguente JSON, come posso produrre un'istanza ResultSet, che trasportano Query valutato ppb?

package jsontest;

import com.google.gson.Gson;

/**
 *
 * @author yccheok
 */
public class Main {

    public static class ResultSet {
        public String Query;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        final String s = "{\"ResultSet\":{\"Query\":\"ppb\"}}";
        System.out.println(s);
        Gson gson = new Gson();
        ResultSet resultSet = gson.fromJson(s, ResultSet.class);
        // {}
        System.out.println(gson.toJson(resultSet));
        // null?
        System.out.println(resultSet.Query);
    }
}

Al momento, qui è ciò che ottengo:

{"ResultSet":{"Query":"ppb"}}
{}
null

Senza modificato la stringa, come posso ottenere un oggetto Java corretto?

È stato utile?

Soluzione

scroll top