开发者

GSON problem in android 2.3.3

开发者 https://www.devze.com 2023-04-02 11:57 出处:网络
I am having trouble serializing to JSON via GSON . Here is my Poll class package com.impact.datacontracts;

I am having trouble serializing to JSON via GSON . Here is my Poll class

package com.impact.datacontracts;

public class Poll {

public int FeedID;
public int Answer;
public Poll(){}
}

I am serializing like this

public void submitPoll(int answerID, int feedID) {
    Poll poll = new Poll();
    poll.Answer = answerID;
    poll.FeedID = feedID;

    Gson gson = new Gson();
    String jsonString = gson.toJson(poll);
    Toast.makeText(_context, jsonString, Toast.LENGTH_LONG).show();

}

in Android 2.2 i get Toast as:

{"FeedID":"1","Answer":"1"}

which is correct , while the same code produces this Toast in Android 2.3.3 :

{"FeedID":"0","Answer":"0"}

but if i change the datatype of FeedID and Answer to String then it works fine in 2.3.3 , i can开发者_C百科 live with Strings but what could be wrong here?

Thanks


Are you trying this out on an HTC device? If yes, you might be a victim of this. Test your app on a vanilla Android device (such as a Nexus One / S or on an emulator). If the problem disappears, you know it was the device's fault and you can easily repackage GSON by following the steps on the aforementioned page.

0

精彩评论

暂无评论...
验证码 换一张
取 消