原本用的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) {
}
}