今天进入项目实训班第一天,由于之前的上课不认真课下没有认真做,面临困难重重。不过还是一一解决了。从前看着大串代码迷茫的json解析今天靠自己也写出来了。
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import us.mifeng.jiangjiajson.Carlist;
import us.mifeng.jiangjiajson.Dealer;
import us.mifeng.jiangjiajson.Json;
import us.mifeng.jiangjiajson.Result;
public class JsonjiangjiaUtils {
public Json getJsonString(String json){
Json jsu = new Json();
JSONObject object;
try {
object = new JSONObject(json);
jsu.setReturncode(object.optInt("returncode"));
Result result = new Result();
JSONObject resultobject = object.getJSONObject("result");
result.setPageindex(resultobject.optInt("pageindex"));
result.setRowcount(resultobject.optInt("rowcount"));
result.setPagecount(resultobject.optInt("41335"));
ArrayList<Carlist>carlists = new ArrayList<Carlist>();
JSONArray carlistArray = resultobject.getJSONArray("carlist");
for(int i =0;i<carlistArray.length();i++){
JSONObject carlistObn = carlistArray.getJSONObject(i);
int specid = carlistObn.optInt("specid");
String specname = carlistObn.optString("specname");
String seriesname = carlistObn.optString("seriesname");
String dealerprice = carlistObn.optString("dealerprice");
String fctprice = carlistObn.optString("fctprice");
int articleid = carlistObn.optInt("articleid");
String enddate = carlistObn.optString("enddate");
String orderrangetitle = carlistObn.optString("orderrangetitle");
String orderrange = carlistObn.optString("orderrange");
Carlist carlist = new Carlist();
carlists.add(carlist);
}
result.setCarlist(carlists);
Dealer dealer = new Dealer();
JSONObject dealerObn = resultobject.getJSONObject("dealer");
dealer.setId(dealerObn.optInt("id"));
dealer.setName(dealerObn.optString("name"));
dealer.setShortname(dealerObn.optString("shortname"));
dealer.setCity(dealerObn.optString("city"));
dealer.setPhone(dealerObn.optString("phone"));
dealer.setPhonestyled(dealerObn.optString("phonestyled"));
dealer.setSpecprice(dealerObn.optString("specprice"));
dealer.setTeltext(dealerObn.optString("teltext"));
dealer.setOrderrange(dealerObn.optString("orderrange"));
result.setCarlist(carlists);
jsu.setResult(result);
} catch (JSONException e) {
e.printStackTrace();
}
return jsu;
}
}
自己的任务就是这个项目的降价页面。已经把降价页面详情完整写出来了。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="15dp"
android:id="@+id/toptView"
android:textSize="12sp"
android:background="#D0D0D0"
android:text="阿斯顿马丁-one77 2012款 超级跑车"
/>
<LinearLayout
android:layout_marginLeft="8dp"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="horizontal"
android:background="#F0F0F0"
>
<ImageView
android:layout_width="85dp"
android:layout_height="85dp"
android:id="@+id/titleimageView"
android:background="@drawable/asidunmading"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="85dp"
android:orientation="vertical"
android:layout_marginLeft="5dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="21dp"
android:id="@+id/zhidaojia_tView"
android:text="指导价:4200万 降203.6万"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="21dp"
android:id="@+id/xiaoshoujia_tView"
android:text="销售价:停售"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="21dp"
android:id="@+id/zuijindingdan_tView"
android:text="最近订单:0笔"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="21dp"
android:id="@+id/jiezhiriqi_tView"
android:text="截止日期:已售磬"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_height="85dp"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_marginLeft="8dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="15dp"
android:text="[4S]鑫华兴汽车"
/>
<TextView
android:layout_marginTop="2dp"
android:layout_width="wrap_content"
android:layout_height="15dp"
android:text="主营品牌:知豆电动车"
android:textSize="11sp"
android:textColor="#D0D0D0"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="20dp"
android:orientation="horizontal">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@drawable/zuobiao"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:text="厦门市海沧区滨湖北路865号之一"
android:layout_gravity="center"
android:textSize="12sp"
android:textColor="#73BF00"/>
</LinearLayout>
<ImageView
android:layout_width="100dp"
android:layout_height="35dp"
android:background="@drawable/bodadianhua"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/jiangjiaxiangqing"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:background="@drawable/button1"
android:text="降价详情"
android:textSize="13sp"/>
<Button
android:id="@+id/canshupeizhi"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:background="@drawable/button2"
android:text="参数配置"
android:textSize="13sp"/>
</LinearLayout>
<WebView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/webview"/>
</LinearLayout>
虽然之间马马虎虎有好多低级错误但是自己都一一解决了总体自我感觉良好还可以接受。
比起以前天天不知道学的什么梦游一样的上课,今天还算有所收获。明天继续。数据解析。