Unicode from JSON works fine for text view on android, assign to string, and it does not work
Basically if I do something like
myTextView.setText(jsonObj.getString(USER_NAME));
My text view will show the correct text : あ
if I do the following:
String myText = jsonObj.getString(USER_NAME);
myTextView.setText(myText);
The text also appears correct & shows : あ
In my use case. I have a class RowRecord & constructor & class var
public class RowRecord {
public String mUserName = "";
public RowRecord (JSONObject jsonObj, Context context) {
mUserName = munzee.getString(Constants.MUNZEE_FRIENDLY_NAME);
}
}
I then have my arrayAdapter
public class MyArray extends ArrayAdapter<RowRecord>
When overriding getView
@Override
public View getView(int position, View convertView, ViewGroup parent) {
RowReco开发者_运维技巧rd rowRecord = getItem(position);
.
.
.
TextView myUserName = (TextView)itemView.findViewById(R.id.txtUserName);
txtUserName.setText(rowRecord.mUserName);
It ends up displaying like あ
So I went and tried to do the following
String myText= new String( jsonObj.getString(USER_NAME).getBytes(), "UTF-16" );
Unfortunately it displayed it as some square boxes.
I then
Any help would be appreciated, Thanks
Look at the raw JSON string, and make sure strings are in the same encoding your code expects. Your safest bet is to use UTF-8 throughout.
精彩评论