本文整理汇总了Java中org.json.JSONObject.getJSONArray方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.getJSONArray方法的具体用法?Java JSONObject.getJSONArray怎么用?Java JSONObject.getJSONArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.getJSONArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: a
import org.json.JSONObject; //导入方法依赖的package包/类
static h a(JSONObject jSONObject) throws JSONException {
if (jSONObject == null) {
return null;
}
h hVar = new h();
JSONObject jSONObject2 = jSONObject.getJSONObject("task_info");
hVar.a = jSONObject2.getString("task_id");
hVar.b = jSONObject2.getString("task_desc");
JSONArray jSONArray = jSONObject2.getJSONArray("step_info");
int length = jSONArray.length();
if (length > 0) {
hVar.c = new g[length];
}
for (int i = 0; i < length; i++) {
jSONObject2 = jSONArray.getJSONObject(i);
hVar.c[i] = new g(jSONObject2.getInt("step_no"), jSONObject2.getString("step_desc"), jSONObject2.getString("step_gift"), jSONObject2.getLong("end_time"), jSONObject2.getInt("status"));
}
return hVar;
}
示例2: getArrayString
import org.json.JSONObject; //导入方法依赖的package包/类
public static String[] getArrayString(JSONObject docObj, String name) {
String[] list = null;
if (docObj.has(name)) {
JSONArray json;
try {
json = docObj.getJSONArray(name);
int lenFeatures = json.length();
list = new String[lenFeatures];
for (int j = 0; j < lenFeatures; j++) {
String f = json.getString(j);
list[j] = f;
}
} catch (JSONException e) {
e.printStackTrace();
}
}
return list;
}
示例3: getQuestionItems
import org.json.JSONObject; //导入方法依赖的package包/类
@Override
public Observable<List<QuestionItem>> getQuestionItems(String value) {
List<QuestionItem> questionItems = new ArrayList<QuestionItem>();
try {
JSONObject jsonObject = new JSONObject(value);
JSONArray array = jsonObject.getJSONArray("data");
for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
JSONArray array1 = object.getJSONArray("list");
List<Question> questions = new ArrayList<Question>();
for (int j = 0; j < array1.length(); j++) {
JSONObject object1 = array1.getJSONObject(j);
Question question = new Question();
question.setAnswer(object1.getString("desc"));
question.setQuestion(object1.getString("title"));
questions.add(question);
}
QuestionItem questionItem = new QuestionItem();
questionItem.setName(object.getString("category"));
questionItem.setQuestion(questions);
questionItems.add(questionItem);
}
} catch (JSONException e) {
e.printStackTrace();
}
return Observable.just(questionItems);
}
示例4: build
import org.json.JSONObject; //导入方法依赖的package包/类
public void build(String data){
try {
// PHP에서 받아온 JSON 데이터를 JSON오브젝트로 변환
JSONObject jObject = new JSONObject(data);
// results라는 key는 JSON배열로 되어있다.
JSONArray results = jObject.getJSONArray("result");
String countTemp = (String)jObject.get("num_result");
int count = Integer.parseInt(countTemp);
for ( int i = 0; i < count; ++i ) {
JSONObject temp = results.getJSONObject(i);
convert(temp);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
示例5: loadFromJSONObject
import org.json.JSONObject; //导入方法依赖的package包/类
@Override
protected void loadFromJSONObject(JSONObject obj, Database db) throws JSONException {
JSONArray aggregateColumns = obj.getJSONArray(Members.AGGREGATE_COLUMNS.name());
for (int ii = 0; ii < aggregateColumns.length(); ii++) {
JSONObject aggregateColumn = aggregateColumns.getJSONObject(ii);
m_aggregateTypes.add(ExpressionType.valueOf(aggregateColumn.getString(Members.AGGREGATE_TYPE.name())));
m_aggregateColumnNames.add(aggregateColumn.getString(Members.AGGREGATE_NAME.name()));
m_aggregateColumnGuids.add(aggregateColumn.getInt(Members.AGGREGATE_GUID.name()));
m_aggregateOutputColumns.add(aggregateColumn.getInt(Members.AGGREGATE_OUTPUT_COLUMN.name()));
}
try {
JSONArray groupbyColumnGuids = obj.getJSONArray(Members.GROUPBY_COLUMNS.name());
for (int ii = 0; ii < groupbyColumnGuids.length(); ii++) {
JSONObject jsonObject = groupbyColumnGuids.getJSONObject(ii);
PlanColumn column = PlanColumn.fromJSONObject(jsonObject, db);
m_groupByColumnGuids.add(column.guid());
}
} catch (JSONException e) {
//okay not to be there.
}
}
示例6: parser
import org.json.JSONObject; //导入方法依赖的package包/类
public RedPacketBean parser(JSONObject data) throws Exception {
parsePollingController(data);
RedPacketBean bean = new RedPacketBean();
if (has(data, "blockContent")) {
JSONArray jsonArray = data.getJSONArray("blockContent");
if (!(jsonArray == null || jsonArray.length() == 0)) {
RedPacketSdkManager.getInstance().setRedPacketList(jsonArray);
}
bean = parserRedPacketList(jsonArray);
bean.type = RedPacketBean.TYPE_REDPACKET;
}
this.mPollingResult.hasRedPacket = RedPacketSdkManager.getInstance().hasRedPacket(bean);
if (this.mCallback != null) {
this.mCallback.onReceivePollingResult(this.mPollingResult);
this.mCallback = null;
}
LogInfo.log("RedPacketParser", "parser + Network is ok,parse polling result is finish");
return bean;
}
示例7: parseItems
import org.json.JSONObject; //导入方法依赖的package包/类
private void parseItems(List<GalleryItem> items, JSONObject jsonBody)
throws IOException, JSONException {
JSONObject photosJsonObject = jsonBody.getJSONObject("photos");
JSONArray photoJsonArray = photosJsonObject.getJSONArray("photo");
for (int i = 0; i < photoJsonArray.length(); i++) {
JSONObject photoJsonObject = photoJsonArray.getJSONObject(i);
GalleryItem item = new GalleryItem();
item.setId(photoJsonObject.getString("id"));
item.setCaption(photoJsonObject.getString("title"));
if (!photoJsonObject.has("url_s")) {
continue;
}
item.setUrl(photoJsonObject.getString("url_s"));
items.add(item);
}
}
示例8: loadFromJSONObject
import org.json.JSONObject; //导入方法依赖的package包/类
protected void loadFromJSONObject(JSONObject object, Database db) throws JSONException {
super.loadFromJSONObject(object, db);
JSONArray executeList = object.getJSONArray(Members.EXECUTE_LIST.name());
for (int ii = 0; ii < executeList.length(); ii++) {
Integer id = executeList.getInt(ii);
m_list.add(m_idToNodeMap.get(id));
}
}
示例9: QoSServerResultDesc
import org.json.JSONObject; //导入方法依赖的package包/类
/**
*
* @param json
* @throws JSONException
*/
public QoSServerResultDesc(JSONObject json) throws JSONException {
this.desc = json.getString(JSON_KEY_DESCRIPTION);
this.testType = QoSTestResultEnum.valueOf(json.getString(JSON_KEY_TESTTYPE));
this.status = DetailType.valueOf(json.getString(JSON_KEY_STATUS).toUpperCase(Locale.US));
JSONArray uidArray = json.getJSONArray(JSON_KEY_UID_LIST);
for (int i = 0; i < uidArray.length(); i++) {
uidSet.add(uidArray.getLong(i));
}
}
示例10: parseUserConnections
import org.json.JSONObject; //导入方法依赖的package包/类
public static ArrayList<UserConnection> parseUserConnections(JSONObject object) {
ArrayList<UserConnection> connections = null;
try {
JSONArray connObj = object.getJSONArray("user_connections");
return (ArrayList) new Gson().fromJson(connObj.toString(), new
TypeToken<ArrayList<UserConnection>>() {
}.getType());
} catch (JSONException e) {
e.printStackTrace();
return connections;
}
}
示例11: parsStreams
import org.json.JSONObject; //导入方法依赖的package包/类
ArrayList<Lydstream> parsStreams(JSONObject jsonobj) throws JSONException {
ArrayList<Lydstream> lydData = new ArrayList<>();
String subtitles = null;
JSONArray jsonArraySubtitles = jsonobj.optJSONArray("SubtitlesList"); //Forventer den kan være tom
if (jsonArraySubtitles != null) {
//Antagelse: Vil altid kun være 1 subtitle, på dansk. Dog tjekkes det i et for-loop og leder efter dansk, hvis nu antagelsen er forkert.
for (int i = 0; i < jsonArraySubtitles.length(); i++) {
JSONObject jsonSubtitles = jsonArraySubtitles.getJSONObject(i);
if (jsonSubtitles.getString("Language").equals("Danish")) {
subtitles = jsonSubtitles.getString("Uri");
} else Log.d("Findes andre subtitles på sprog: " + jsonSubtitles.getString("Language"));
}
}
JSONArray jsonArrayStreams = jsonobj.getJSONArray("Links");
for (int k = 0; k < jsonArrayStreams.length(); k++) {
JSONObject jsonStream = jsonArrayStreams.getJSONObject(k);
String type = jsonStream.getString("Target");
if ("HDS".equals(type)) continue; // HDS (HTTP Dynamic Streaming fra Adobe) kan ikke afspilles på Android
//if (App.fejlsøgning) Log.d("streamjson=" + jsonStream);
Lydstream l = new Lydstream();
l.url = jsonStream.getString("Uri");
if ("Download".equals(type)) {
l.type = Lydstream.StreamType.HTTP_Download;
l.bitrate_ubrugt = jsonStream.getInt("Bitrate");
} else {
l.type = Lydstream.StreamType.HLS_fra_Akamai;
}
l.kvalitet = Lydstream.StreamKvalitet.Variabel;
l.subtitlesUrl = subtitles;
lydData.add(l);
}
return lydData;
}
示例12: handleWeatherResponse
import org.json.JSONObject; //导入方法依赖的package包/类
/**
*
* 处理得到的 weather 数据,转化为 weather 对象
*/
public static Weather handleWeatherResponse(String response){
try{
JSONObject jsonObject = new JSONObject(response);
JSONArray jsonArray = jsonObject.getJSONArray("HeWeather5");
String weatherContent = jsonArray.getJSONObject(0).toString();
return new Gson().fromJson(weatherContent, Weather.class);
}catch (Exception e){
e.printStackTrace();
}
return null;
}
示例13: downloadComment
import org.json.JSONObject; //导入方法依赖的package包/类
private void downloadComment() {
StringRequest strReq = new StringRequest(Request.Method.POST,
AppConfig.URL_COMMENTS, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jObj = new JSONObject(response);
JSONArray feedArray = jObj.getJSONArray("comments");
adapter.CommentsList.clear();
for (int i = 0; i < feedArray.length(); i++) {
final JSONObject feedComment = (JSONObject) feedArray.get(i);
//add product to list products
Comments comment = new Comments(feedComment.getString("userid"), feedComment.getString("username"), feedComment.getString("time"),
feedComment.getString("contentcomment"), feedComment.getString("userpic"), feedComment.getString("rate"));
adapter.CommentsList.add(comment);
}
// Load detail fragment if in tablet mode
commentView.setAdapter(adapter);
adapter.notifyDataSetChanged();
} catch (Exception ex) {
// JSON parsing error
ex.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<>();
params.put("userid", userid + "");
return params;
}
};
strReq.setTag(this.getClass().getName());
VolleySingleton.getInstance(getActivity()).requestQueue.add(strReq);
}
示例14: onPostExecute
import org.json.JSONObject; //导入方法依赖的package包/类
protected void onPostExecute(String response) {
if (response == null) {
response = "THERE WAS AN ERROR";
}
progressBar.setVisibility(View.GONE);
Log.i("INFO", response);
//responseView.setText(response);
try {
JSONObject object = (JSONObject) new JSONTokener(response).nextValue();
JSONArray obj1 = object.getJSONArray("result");
JSONObject obj = obj1.getJSONObject(0);
// String email1 = obj.getString("country");
// System.out.println(email1);
int rating1 = 0, maxrating1 = 0;
String country1 = null, city1 = null, contribution1 = null, firstname = null, lastname = null;
if (obj.has("rating"))
rating1 = obj.getInt("rating");
if (rating1 != 0)
rating.setText(rating1 + "");
else rating.setText("Not Found ");
if (obj.has("country"))
country1 = obj.getString("country");
else country1 = "Not Found ";
country.setText(country1);
if (obj.has("city"))
city1 = obj.getString("city");
else city1 = "Not Found ";
city.setText(city1);
if (obj.has("maxRating"))
maxrating1 = obj.getInt("maxRating");
if (maxrating1 != 0)
maxrating.setText(maxrating1 + "");
else maxrating.setText("Not Found");
if (obj.has("contribution"))
contribution1 = obj.getString("contribution");
else contribution1 = "Not Found";
contribution.setText(contribution1);
if (obj.has("firstName"))
firstname = obj.getString("firstName");
else firstname = "Not Found";
if (obj.has("lastName"))
lastname = obj.getString("lastName");
else lastname = "";
username.setText(firstname + " " + lastname);
submission.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = "http://codeforces.com/submissions/" + handle.getText().toString();
}
});
} catch (JSONException e) {
e.printStackTrace();
}
// try {
// JSONObject object = (JSONObject) new JSONTokener(response).nextValue();
// String requestID = object.getString("requestId");
// int likelihood = object.getInt("likelihood");
// JSONArray photos = object.getJSONArray("photos");
// .
// .
// .
// .
// } catch (JSONException e) {
// e.printStackTrace();
// }
}
示例15: getArtwork
import org.json.JSONObject; //导入方法依赖的package包/类
public void getArtwork(Track track) {
final String currentArtist = "" + track.getArtist();
if (currentArtist.equals(""))
return;
if (MediaUtils.getArtworkQuick(context, track, 300, 300) != null)
return;
if (activeTasks.size() > 2)
return;
if (activeTasks.containsKey(currentArtist))
return;
activeTasks.put(currentArtist, this);
AQuery aq = new AQuery(context);
String url = String.format("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&api_key=683548928700d0cdc664691b862a8d21&artist=%s&format=json", Uri.encode(currentArtist));
AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>();
cb.url(url).type(JSONObject.class).fileCache(true).expire(3600 * 60 * 1000);
aq.sync(cb);
JSONObject result = cb.getResult();
if (result != null) {
JSONObject jsonObject = null;
String albumArtImageLink = null;
try {
if (!result.has("artist"))
return;
jsonObject = result.getJSONObject("artist");
JSONArray image = jsonObject.getJSONArray("image");
for (int i=0;i<image.length();i++) {
jsonObject = image.getJSONObject(i);
if (jsonObject.getString("size").equals("extralarge")) {
albumArtImageLink = Uri.decode(jsonObject.getString("#text"));
}
}
if (!(albumArtImageLink != null && albumArtImageLink.equals(""))) {
String path = MediaUtils.getArtistPath(track);
if (path != null) {
File file = new File(path);
AjaxCallback<File> cbFile = new AjaxCallback<File>();
cbFile.url(albumArtImageLink).type(File.class).targetFile(file);
aq.sync(cbFile);
AjaxStatus status = cbFile.getStatus();
if (status.getCode() == 200) {
if (listener != null)
listener.onNewArtwork();
} else {
file.delete();
}
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
activeTasks.remove(currentArtist);
}