网站上json文件格式
{
"success": true,
"respinfo": null,
"total": 15,
"rows": [
{
"paramVersion": "1",
"menuCode": "B001",
"upMenuCode": "1",
"menuType": "9",
"menuName": "银行",
"menuDisp": null,
"menuLogo": "/images/bank.png",
"menuSort": "100",
"menuPath": null,
"keyWord": "人民广场",
"range": "100",
"lastUptTime": "20141031153210",
"lastUptAcc": null,
"lastUptOrg": null
},
{
"paramVersion": "1",
"menuCode": "B002",
"upMenuCode": "1",
"menuType": "2",
"menuName": "酒吧",
"menuDisp": null,
"menuLogo": "/images/bar.png",
"menuSort": "200",
"menuPath": null,
"keyWord": "漕河泾",
"range": "200",
"lastUptTime": "20141103153210",
"lastUptAcc": null,
"lastUptOrg": null
},
{
"paramVersion": "1",
"menuCode": "B003",
"upMenuCode": "1",
"menuType": "9",
"menuName": "公交",
"menuDisp": null,
"menuLogo": "/images/bus.png",
"menuSort": "300",
"menuPath": null,
"keyWord": "豫园",
"range": "400",
"lastUptTime": "20141103153210",
"lastUptAcc": null,
"lastUptOrg": null
},
{
"paramVersion": "1",
"menuCode": "B004",
"upMenuCode": "1",
"menuType": "1",
"menuName": "电影院",
"menuDisp": null,
"menuLogo": "/images/cinema.png",
"menuSort": "400",
"menuPath": null,
"keyWord": "植物园",
"range": "600",
"lastUptTime": "20141103153210",
"lastUptAcc": null,
"lastUptOrg": null
},
{
"paramVersion": "1",
"menuCode": "B005",
"upMenuCode": "1",
"menuType": "1",
"menuName": "咖啡厅",
"menuDisp": null,
"menuLogo": "/images/coffee.png",
"menuSort": "500",
"menuPath": null,
"keyWord": "大宁商业广场",
"range": "500",
"lastUptTime": "20141103153210",
"lastUptAcc": null,
"lastUptOrg": null
},
{
"paramVersion": "1",
"menuCode": "B006",
"upMenuCode": "1",
"menuType": "1",
"menuName": "其他",
"menuDisp": null,
"menuLogo": "/images/else.png",
"menuSort": "600",
"menuPath": null,
"keyWord": "佘山公园",
"range": "800",
"lastUptTime": "20141104153210",
"lastUptAcc": null,
"lastUptOrg": null
},
{
"paramVersion": "1",
"menuCode": "B007",
"upMenuCode": "1",
"menuType": "1",
"menuName": "美食",
"menuDisp": null,
"menuLogo": "/images/food.png",
"menuSort": "700",
"menuPath": null,
"keyWord": "灵石公园",
"range": "300",
"lastUptTime": "20141104153210",
"lastUptAcc": null,
"lastUptOrg": null
},
{
"paramVersion": "1",
"menuCode": "B008",
"upMenuCode": "B001",
"menuType": "1",
"menuName": "医院",
"menuDisp": null,
"menuLogo": "/images/hospital.png",
"menuSort": "101",
"menuPath": null,
"keyWord": "定位菊花",
"range": "200",
"lastUptTime": "20141104153210",
"lastUptAcc": null,
"lastUptOrg": null
},
{
"paramVersion": "1",
"menuCode": "B009",
"upMenuCode": "B001",
"menuType": "1",
"menuName": "酒店",
"menuDisp": null,
"menuLogo": "/images/hotel.png",
"menuSort": "102",
"menuPath": null,
"keyWord": "定位玫瑰",
"range": "200",
"lastUptTime": "20141104153210",
"lastUptAcc": null,
"lastUptOrg": null
},
{
"paramVersion": "1",
"menuCode": "B010",
"upMenuCode": "B002",
"menuType": "1",
"menuName": "停车场",
"menuDisp": null,
"menuLogo": "/images/p.png",
"menuSort": "201",
"menuPath": null,
"keyWord": "西餐地址列表",
"range": "700",
"lastUptTime": "20141104153210",
"lastUptAcc": null,
"lastUptOrg": null
},
{
"paramVersion": "1",
"menuCode": "B011",
"upMenuCode": "1",
"menuType": "1",
"menuName": "超市",
"menuDisp": null,
"menuLogo": "/images/shopping.png",
"menuSort": "1000",
"menuPath": null,
"keyWord": null,
"range": "800",
"lastUptTime": "20141104153210",
"lastUptAcc": null,
"lastUptOrg": null
},
{
"paramVersion": "1",
"menuCode": "B112",
"upMenuCode": "B003",
"menuType": "1",
"menuName": "公共厕所",
"menuDisp": null,
"menuLogo": "/images/toilet.png",
"menuSort": "1200",
"menuPath": null,
"keyWord": null,
"range": "100",
"lastUptTime": "20141104153210",
"lastUptAcc": null,
"lastUptOrg": null
},
{
"paramVersion": "1",
"menuCode": "G001",
"upMenuCode": "1",
"menuType": "1",
"menuName": "加油站",
"menuDisp": null,
"menuLogo": "/images/gas_station.png",
"menuSort": "800",
"menuPath": null,
"keyWord": "上海动物园",
"range": "1000",
"lastUptTime": "20141104153210",
"lastUptAcc": null,
"lastUptOrg": null
},
{
"paramVersion": "1",
"menuCode": "G002",
"upMenuCode": "1",
"menuType": "1",
"menuName": "公共机构",
"menuDisp": null,
"menuLogo": "/images/gong gong ji gou.png",
"menuSort": "900",
"menuPath": null,
"keyWord": "广中西路肯德基",
"range": "100",
"lastUptTime": "20141104153210",
"lastUptAcc": null,
"lastUptOrg": null
},
{
"paramVersion": "1",
"menuCode": "G003",
"upMenuCode": "1",
"menuType": "1",
"menuName": "便利店",
"menuDisp": null,
"menuLogo": "/images/store.png",
"menuSort": "1100",
"menuPath": null,
"keyWord": null,
"range": "200",
"lastUptTime": "20141104153210",
"lastUptAcc": null,
"lastUptOrg": null
}
]
}
更具menuSor的大小从小到大排序显示到如下布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:padding="4dp"
android:scaleType="fitXY" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView"
android:layout_centerInParent="true"
android:gravity="center"
android:lines="1"
android:textColor="#ffffff" />
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0000FF"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="85dp"
android:gravity="center"
android:text="周围有啥"
android:textColor="#ffffff"
android:textSize="30dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >
<GridView
android:id="@+id/MyGridView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="20dp"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="5dp"
android:numColumns="auto_fit"
android:scrollbars="none"
android:verticalSpacing="3dp" />
</LinearLayout>
</LinearLayout>
求大神能指教 谢谢
------解决思路----------------------
用自带的JsonObject和JsonArray
------解决思路----------------------
楼主是不会解析还是不会显示呢?
按照你的这个json格式先定义两个个数据modle,M_A,M_B,M_A中有一个list<M_B>,请求数据,返回的jstr,通过jstr,jsonObject = new JSONObject(jstr);然后
if (list<M_B> b_list; jsonObject.has("rows")) { JSONArray jsonArray = jsonObject.getJSONArray("rows");for (int i = 0; i < jsonArray.length(); i++) {M_B m_b; JSONObject listObject; listObject = jsonArray.getJSONObject(i);String s = listObject.getString(“paramVersion”); m_b.paramVersion= s, b_list.add(m_b);} M_A m_a; m_a.setM_BList(b_list);}上面的是解析,显示的话应该就明白了。大概思路是这样的,中间的代码是我随手写的,只是逻辑。
------解决思路----------------------
直接上代码
JSONTokener jsontokener = new JSONTokener(strjson);
JSONObject object = (JSONObject) jsontokener.nextValue();
String success = object.getString("success");
。。。
success 就可以直接设到画面上了。
String rows= object.getString("rows");
JSONArray new JSONArray(rows)
int size = jsonarray.length();
for (int i = 0; i < size; i++) {
JSONObject jsonobject = jsonarray.getJSONObject(i);
String paramVersion=jsonobject.getString("paramVersion");
...
}
当然有多条,不可能用String来保存,自己定义list之类的就可以搞定了!
只能说到这样了!
------解决思路----------------------
可以用JSONObejct解析成JSONObejct对象,再采用gson包下的GSON解析成实体对象, 我的android项目里面就是这么做的, 非常方便