InputStream open = getAssets().open("Activity.json"); ByteArrayOutputStream stream = new ByteArrayOutputStream(); byte[] arr = new byte[1024]; int length; while ((length = open.read(arr, 0, arr.length)) != -1) { stream.write(arr, 0, length); } s = new String(stream.toByteArray(), StandardCharsets.UTF_8); Log.d(TAG, "onClick: " + s); JSONObject object = new JSONObject(s); JSONArray activity = object.getJSONArray("activity"); JSONObject object1 = new JSONObject(); object1.put("action", "android.intent.action.MyIntent"); JSONArray jsonArray = new JSONArray(); jsonArray.put(0, "00000000000"); jsonArray.put(1, "11111111111"); jsonArray.put(2, "22222222222"); object1.putOpt("hello", jsonArray); activity.put(object1); Log.d(TAG, "onClick: " + activity.toString()); JSONObject jsonObject = activity.getJSONObject(0); String action = jsonObject.getString("action"); Log.d(TAG, "onClick: " + activity.toString()); Intent intent = new Intent(); intent.setAction(action); intent.addCategory(Intent.CATEGORY_DEFAULT); startActivity(intent);
Json解析
最新推荐文章于 2022-04-24 10:38:11 发布