iT邦幫忙

0

android json

  • 分享至 

  • xImage

原本用的json是資料直接打在程式碼裡,現在想要抓URL但是看了很多偏範例,還是不會改,怎麼把它改成用URL抓並且一樣是URLData

@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		newContext = getActivity();
		try {
			URLData = new JSONObject(
					"{"error":"ok","status":0,"data":[{"Art":5,"news":450,"bkk":680},{"Art":5,"news":460,"bkk":690}]}")
.getJSONArray("data");
} catch (JSONException e) {
		}
	}
@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.watch, null);
		List<TimesEntity> watchList = new ArrayList<TimesEntity>();
		JSONObject data = null;
		try {
			for (int i = 0; i < URLData.length(); i++) {
				data = URLData.getJSONObject(i);
				timesList.add(new TimesEntity(data.getString("Art"), data.getDouble("news"), data.getDouble("bkk")));
			}
		} catch (Exception e) {	
		}
	}    
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
海綿寶寶
iT邦大神 1 級 ‧ 2017-06-25 13:08:07
c5488 iT邦新手 5 級 ‧ 2017-07-02 20:15:29 檢舉

看很久還是改不好,真困難

c5488 iT邦新手 5 級 ‧ 2017-07-02 20:17:06 檢舉

主要是這段的資料要改成從URL接收,但改不好

try {
			URLData = new JSONObject(
					"{"error":"ok","status":0,"data":[{"Art":5,"news":450,"bkk":680},{"Art":5,"news":460,"bkk":690}]}")
.getJSONArray("data");

我要發表回答

立即登入回答