Skip to content

Instantly share code, notes, and snippets.

@toguri
Created January 29, 2015 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toguri/00a66bc5d085583dd9eb to your computer and use it in GitHub Desktop.
Save toguri/00a66bc5d085583dd9eb to your computer and use it in GitHub Desktop.
JSON作成時に、特定の機種のみで発生してたこと
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*
JSON作成時に、特定の機種のみで発生してたこと
SH-04E (4.1.2)の場合
{"hoge":["111111111","2222222222","3333333333"]}
{"foo":"[111111111, 2222222222, 3333333333]"}
Nexus5 (4.4.4)の場合
{"hoge":["111111111","2222222222","3333333333"]}
{"foo":["111111111", "2222222222", "3333333333"]}
*/
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("111111111");
arrayList.add("2222222222");
arrayList.add("3333333333");
JSONArray jsonArray = new JSONArray(arrayList);
// JSONArrayに変換してからつっこむ
HashMap<String, Object> map = new HashMap<String, Object>(1);
map.put("hoge", jsonArray);
Log.d("MainActivity", new JSONObject(map).toString());
// ArrayListに変換してからつっこむ
HashMap<String, Object> map2 = new HashMap<String, Object>(1);
map2.put("foo", arrayList);
Log.d("MainActivity", new JSONObject(map2).toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment