1.最近做的一个项目中传递的数据类型是Json格式的,所以在封装数据的时候要很清晰的表达传输数据的层次关系。在这里我简单的把自己封装成的一个比较规范的json,展示下!
这里我实在应用程序启动的时候就得到device的一些信息。
主要方法在这个Activity中。
package com.funo.jsonObject;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.os.Build;
import android.telephony.TelephonyManager;
public class json {
public static void onResume(Context paramContext) {
JSONObject localJSONObject = new JSONObject();
try {
localJSONObject.put("type", "launch");
localJSONObject.put("session_id", "dsds");
localJSONObject.put("date", "3=4-3");
localJSONObject.put("time", "23-3-3");
} catch (JSONException localJSONException) {
localJSONException.printStackTrace();
}
SendThread(paramContext, localJSONObject);
}
private static void SendThread(Context paramContext,
JSONObject paramJSONObject) {
JSONObject localJSONObject1 = getDeviceJson(paramContext);
JSONObject localJSONObject3 = new JSONObject();
JSONObject localJSONObject2 = new JSONObject();
JSONArray localJSONArray;
localJSONArray = new JSONArray();
localJSONArray.put(paramJSONObject);
try {
localJSONObject2.put("terminate", localJSONArray);
localJSONObject2.put("launch", localJSONArray);
localJSONObject3.put("body", localJSONObject2);
localJSONObject3.put("header", localJSONObject1);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(localJSONObject3.toString());
}
private static JSONObject getDeviceJson(Context paramContext) {
JSONObject localJSONObject = new JSONObject();
try {
localJSONObject.put("idmd5", "idmd5");
localJSONObject.put("device_model", Build.MODEL);
localJSONObject.put("appkey", "appkey");
localJSONObject.put("sdk_type", "Android");
localJSONObject.put("sdk_version", "3.1.1");
localJSONObject.put("os", "Android");
localJSONObject.put("os_version", Build.VERSION.RELEASE);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return localJSONObject;
}
}
main.xml 使用者可以随便。不用当然也是可以的啦!
在下面会附上得到的结果,在配置文件记得加上一些权限。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.funo.jsonObject"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="JsonObjectActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
。
- 大小: 8.1 KB
分享到:
相关推荐
Android开发-Fragment JsonObject JsonArray 综合运用-AndroidStudio http://blog.csdn.net/iwanghang/article/details/52488420
一、JSONObject和JSONArray的数据表示形式 JSONObject的数据是用 { } 来表示的, 例如: { id : 123, courseID : huangt-test, title : 提交作业, content : null } 而JSONArray,顾名思义是由JSONObject构成...
JSONObject与JSONArray使用中所需要的完全jar包整理、需要依赖的包:commons-lang.jar commons-beanutils.jar commons-collections.jar commons-logging.jar ezmorph.jar json-lib-2.2.2-jdk15.jar...
jsonObject, jsonArray所需的6个jar包 json-lib-2.4-jdk15.jar; ezmorph-1.0.6.jar; commons-logging-1.1.1.jar; commons-lang-2.4.jar; commons-collections-3.2.1.jar; commons-beanutils-1.8.3.jar;
JSONObject、JSONArray需要的jar包,需要的可以直接联系
JSONObject与JSONArray所需jar包 ===JSONObject与JSONArray所需jar包
JSON使用阿里的fastJson为依赖包 gradle依赖管理如下: ...1、String转JSONObject 前言:String 是JSONObject格式的字符串 eg: JSONObject jSONObject = JSONObject....JSONArray jsonArray= JSONArray.parseAr
JSONObject JSONArray JavaBean和json数据的转换等,都可以使用。
JSONObject和JSONArray使用手册.pdfJSONObject和JSONArray使用手册.pdf
JSONObject与JSONArray的使用.pdfJSONObject与JSONArray的使用.pdf
从Kesho推拉的有用库
一....二.具体转化过程 //JSONObject String jsonMessage = "{\"语文\":\"88\",\"数学\":\"78\",\"计算机\":\"99\"}...JSONObject myJsonObject = new JSONObject(jsonMessage); //获取对应的值 value1 = myJsonObject.g
主要介绍了Java中JSONObject与JSONArray的使用区别详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
JSON api JSONObject JSONArray
JsonObject 与JsonArray 使用时的相关最新jar包(用于java 解析json)
解析json的工具类,包括JSONObject、JSONArray、JSONException、JSONString等
NULL 博文链接:https://duduli.iteye.com/blog/1701823
json.jar jsonObject jsonArray jsonString
主要介绍了JSONObject与JSONArray使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
安卓/java与服务器端数据交互所需jar包 JsonObject JsonArray HttpSevelet