json原生解析
2021-07-10 16:04
标签:oda 适配器 instance sites art ddr stat protected this 身为新手,在运用网络解析json数据的时候,发现先会用Gson等框架解析json,然后就懒起来学原生解析了,这下在看别人写的demo的时候就尴尬了,一块块的,不懂写什么,气氛十分尴尬。 不多说,先来条好bolg的链接:http://blog.csdn.net/android_lyp/article/details/52072822 JSON对数据的描述形式,既然是形式,那么它的数据形式是什么样的: 原生解析个人不推荐用,因为加载数据的性能比较低,如果写的界面适配器写的不好等因素加起来的话,加载数据就很慢很慢,现在有很多热门的库类例如Gson等等 Activity中的网络解析(因为没用框架,所以代码会臃肿但是方便开发 ,不利于后面维护) bean 其实,后台传来的数据不止那么少对象,我们来看看后台传过来的json格式是什么 这样的json数据就只是需要几个属性,不用全部拿取,所以原生解析可以很快取得,Gson要实体类多,但是可以很快取得数据,还有让代码简洁。 以下附上Gson解析json的例子传送门:http://blog.csdn.net/tkwxty/article/details/34474501/ json原生解析 标签:oda 适配器 instance sites art ddr stat protected this 原文地址:http://www.cnblogs.com/mrszhou/p/7083142.html
package com.tfot.hotel.yichengyiyu.Activity.zhou_activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.FormEncodingBuilder;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import com.tfot.hotel.yichengyiyu.Activity.NewActivivty.XiangQingActivity;
import com.tfot.hotel.yichengyiyu.Activity.NewActivivty.XiangQingActivity_Long;
import com.tfot.hotel.yichengyiyu.Activity.zhou_activity.adapter.ChaXunJieGuoAdapter;
import com.tfot.hotel.yichengyiyu.Activity.zhou_activity.bean.ChaXunJieGuo;
import com.tfot.hotel.yichengyiyu.R;
import com.tfot.hotel.yichengyiyu.Util.Common;
import com.tfot.hotel.yichengyiyu.Util.base.BaseActivity;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import rx.subscriptions.CompositeSubscription;
/**
* 查询结果界面
* Created by huizhou on 2017/6/26.
*/
public class ChaXunJieGuoActivity extends BaseActivity {
private List
package com.tfot.hotel.yichengyiyu.Activity.zhou_activity.bean;
import java.io.Serializable;
import java.util.ArrayList;
/**
* Created by huizhou on 2017/6/26.
*/
public class ChaXunJieGuo implements Serializable {
private String RoomStyleId;
private String Unitprice;
private String evaluate;
private String Brandname;
private ArrayList
[
{
"RoomStyleId":"51",
"RoomStyleName":"商务双床",
"RoomStyleAddres":"佛山市南海区桂澜北路万达广场C座",
"RoomStylePrice":"2720",
"RoomStyleguarantee":"3860",
"RoomStyleLng":"113.156684",
"RoomStyleLat":"23.063305",
"RoomStyleSize":"58",
"RoomStyleHall":"1",
"RoomStyleRoom":"1",
"RoomStyleToilet":"1",
"RoomStyleEquipage":[
"无线WIFI",
"二十四小时热水",
"二十四小时小时监控",
"床上用品",
"冰箱",
"电视",
"二十四小时小时保安值守",
"空调",
"停车场",
"前台问询"
],
"RoomStylePlan":[
{
"duration":"12",
"price":"2720",
"discount":"0.95",
"total":"2584"
},
{
"duration":"11",
"price":"2750",
"discount":"0.95",
"total":"2613"
},
{
"duration":"10",
"price":"2780",
"discount":"0.95",
"total":"2641"
},
{
"duration":"9",
"price":"2800",
"discount":"0.95",
"total":"2660"
},
{
"duration":"8",
"price":"2830",
"discount":"0.95",
"total":"2689"
},
{
"duration":"7",
"price":"2860",
"discount":"0.95",
"total":"2717"
},
{
"duration":"6",
"price":"3150",
"discount":"0.95",
"total":"2993"
},
{
"duration":"5",
"price":"3290",
"discount":"0.95",
"total":"3126"
},
{
"duration":"4",
"price":"3430",
"discount":"0.95",
"total":"3259"
},
{
"duration":"3",
"price":"3580",
"discount":"0.95",
"total":"3401"
},
{
"duration":"2",
"price":"3720",
"discount":"0.95",
"total":"3534"
},
{
"duration":"1",
"price":"3860",
"discount":"0.95",
"total":"3667"
}
],
"RoomStyleMemo":"2513酒店公寓",
"RoomStyleCItyID":"29",
"RoomStyleProvince":"广东省",
"RoomStyleCIty":"佛山市",
"RoomStyleCounty":"南海区",
"DayDeposit":"100",
"Roomlongrentom":"105",
"RoomStyleImage":[
"./uploadimages/59488cab6c39b.jpg",
"./uploadimages/59488cae23476.jpg",
"./uploadimages/59488cb110cb8.jpg",
"./uploadimages/59488cb3ef3cb.jpg"
],
"Brand":{
"Brandid":"4",
"Brandname":"2513酒店公寓",
"Brandmemo":"2513酒店公寓",
"Brandimage":"./uploadimages/5948e73f7f744.png",
"Brandbigimage":"./uploadimages/5948e72801409.jpg",
"Brandminiimage":"./uploadimages/5948e738cc353.png",
"":"./uploadimages/5948e746c84b4.png"
},
"Unitprice":"218",
"RoomStar":"5",
"evaluate":"10",
"RoomServerManager":{
"ServerManagerId":"16",
"ServerManagerImage":"./uploadimages/58b0f4e08c3f0.png",
"ServerManagerName":"吴柯丽",
"ServerManagerPhoneNumber":"18675739089",
"ServerManagerMemo":"南海管家"
}
}]
上一篇:前端工程师必备的几个实用网站
下一篇:网站后台登录