本文整理了Java中org.json.JSONObject.toJSONArray()
方法的一些代码示例,展示了JSONObject.toJSONArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.toJSONArray()
方法的具体详情如下:
包路径:org.json.JSONObject
类名称:JSONObject
方法名:toJSONArray
[英]Returns an array with the values corresponding to names. The array contains null for names that aren't mapped. This method returns null if names is either null or empty.
[中]返回一个数组,该数组的值与名称对应。对于未映射的名称,数组包含null。如果名称为null或为空,则此方法返回null。
代码示例来源:origin: loklak/loklak_server
/**
* Produce a comma delimited text from a JSONArray of JSONObjects using
* a provided list of names. The list of names is not included in the
* output.
* @param names A JSONArray of strings.
* @param ja A JSONArray of JSONObjects.
* @return A comma delimited text.
* @throws JSONException
*/
public static String toString(JSONArray names, JSONArray ja)
throws JSONException {
if (names == null || names.length() == 0) {
return null;
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < ja.length(); i += 1) {
JSONObject jo = ja.optJSONObject(i);
if (jo != null) {
sb.append(rowToString(jo.toJSONArray(names)));
}
}
return sb.toString();
}
}
代码示例来源:origin: b3log/latke
/**
* Produce a comma delimited text from a JSONArray of JSONObjects using
* a provided list of names. The list of names is not included in the
* output.
* @param names A JSONArray of strings.
* @param ja A JSONArray of JSONObjects.
* @return A comma delimited text.
* @throws JSONException
*/
public static String toString(JSONArray names, JSONArray ja)
throws JSONException {
if (names == null || names.length() == 0) {
return null;
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < ja.length(); i += 1) {
JSONObject jo = ja.optJSONObject(i);
if (jo != null) {
sb.append(rowToString(jo.toJSONArray(names)));
}
}
return sb.toString();
}
}
代码示例来源:origin: wythe0102/Mall
public JSONArray toJSONArray(JSONArray names) throws JSONException {
return jsonObject.toJSONArray(names);
}
代码示例来源:origin: stackoverflow.com
JSONObject jsonObject= new JSONObject(YOUR_STRING);
String[] names = JSONObject.getNames(jsonObject);
JSONArray jsonArray = jsonObject.toJSONArray(new JSONArray(names));
JSONObject id= jsonArray.getJSONObject(0).getJSONObject("id");
person.put("VALUE", id);
代码示例来源:origin: stackoverflow.com
@Override
public void onResponse(JSONObject response) {
try {
JSONObject lesMotsObject = response.getJSONObject("lesMots");
JSONArray jsonArray = lesMotsObject.toJSONArray(lesMotsObject.names());
for (int i = 0; i < jsonArray.length();i++){
JSONObject word = jsonArray.getJSONObject(i);
String wordFrench = word.getString("wordFrench");
String wordEnglish = word.getString("wordEnglish");
...
代码示例来源:origin: stackoverflow.com
quoteHashMap = new HashMap<String,String>();
JSONObject actualObject = query.getJSONObject("query");
JSONObject quote = query.getJSONObject("quote");
JSONArray names = quote.names();
JSONArray quoteArray = quote.toJSONArray(names);
for(int i = 0; i < quoteArray.length(); i++){
String value = quoteArray.getJSONObject(i).getString("value");
String name = quoateArray.getJSONObject(i).getString("name");
quoteHashMap.put(name, value);
}
代码示例来源:origin: stackoverflow.com
try {
JSONObject jsonObject = new JSONObject(response.toString());
JSONArray js = jsonObject.names();
JSONArray val = jsonObject.toJSONArray(js);
List ll = getListFromJsonArray(val);
lv.setAdapter(new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_1, ll));
}catch(Exception e){
}
代码示例来源:origin: stackoverflow.com
JSONObject json = new JSONObject(strResponse);
//Get the element that holds the internship ( JSONArray )
JSONArray name = json.names();
JSONArray internships = json.toJSONArray(name);
代码示例来源:origin: stackoverflow.com
JSONObject jsonObject = new JSONObject(result);
JSONArray jsonArray = jsonObject.toJSONArray(jsonObject.names());
System.out.println(jsonArray); // prints:
// [1,"Available","48.412583|10.0385","An der Decke",1,null,"Virtual",null]
代码示例来源:origin: stackoverflow.com
JSONObject jsonObj = new JSONObject(JsonResponseString);
JSONArray data1 = jsonObj.getJSONArray("Result");
JSONObject obj2 = (JSONObject) data1.get(0);
JSONArray nameArray = obj2.names();
JSONArray valArray = obj2.toJSONArray(nameArray);
String status="";
String gameId="";
for(int i=0 ; i<valArray.length() ; i++){
String name = nameArray.getString(i);
String value = valArray.getString(i);
if (value.equals("null")) {
value = "";
}
if (name.equalsIgnoreCase(Constants.Key_1)) {
Log.v(Constants.LOG, + value);
} else if (name.equalsIgnoreCase(Constants.Key_2)) {
Log.v(Constants.LOG, + value);
} else if (name.equalsIgnoreCase(Constants.Key_3)) {
Log.v(Constants.LOG, + value);
}
}
代码示例来源:origin: stackoverflow.com
JSONObject json = new JSONObject(jsonstring);
JSONArray nameArray = json.names();
JSONArray valArray = json.toJSONArray(nameArray);
JSONArray valArray1 = valArray.getJSONArray(1);
valArray1.toString().replace("[", "");
valArray1.toString().replace("]", "");
int len = valArray1.length();
for (int i = 0; i < valArray1.length(); i++) {
Country country = new Country();
JSONObject arr = valArray1.getJSONObject(i);
country.setCountryCode(arr.getString("countryCode"));
country.setCountryName(arr.getString("countryName"));
arrCountries.add(country);
}
代码示例来源:origin: stackoverflow.com
JSONObject json = new JSONObject(jsonstring);
JSONArray nameArray = json.names();
JSONArray valArray = json.toJSONArray(nameArray);
JSONArray valArray1 = valArray.getJSONArray(1);
valArray1.toString().replace("[", "");
valArray1.toString().replace("]", "");
int len = valArray1.length();
for (int i = 0; i < valArray1.length(); i++) {
Country country = new Country();
JSONObject arr = valArray1.getJSONObject(i);
country.setCountryCode(arr.getString("countryCode"));
country.setCountryName(arr.getString("countryName"));
arrCountries.add(country);
}
代码示例来源:origin: org.apache.abdera/json
/**
* Produce a comma delimited text from a JSONArray of JSONObjects using
* a provided list of names. The list of names is not included in the
* output.
* @param names A JSONArray of strings.
* @param ja A JSONArray of JSONObjects.
* @return A comma delimited text.
* @throws JSONException
*/
public static String toString(JSONArray names, JSONArray ja)
throws JSONException {
if (names == null || names.length() == 0) {
return null;
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < ja.length(); i += 1) {
JSONObject jo = ja.optJSONObject(i);
if (jo != null) {
sb.append(rowToString(jo.toJSONArray(names)));
}
}
return sb.toString();
}
}
代码示例来源:origin: stackoverflow.com
JSONObject json = new JSONObject(jsonstring);
JSONArray nameArray = json.names();
JSONArray valArray = json.toJSONArray(nameArray);
JSONArray valArray1 = valArray.getJSONArray(1);
valArray1.toString().replace("[", "");
valArray1.toString().replace("]", "");
int len = valArray1.length();
for (int i = 0; i < valArray1.length(); i++) {
Country country = new Country();
JSONObject arr = valArray1.getJSONObject(i);
country.setCountryCode(arr.getString("countryCode"));
country.setCountryName(arr.getString("countryName"));
arrCountries.add(country);
}
代码示例来源:origin: stackoverflow.com
JSONObject json = new JSONObject(jsonstring);
JSONArray nameArray = json.names();
JSONArray valArray = json.toJSONArray(nameArray);
JSONArray valArray1 = valArray.getJSONArray(1);
valArray1.toString().replace("[", "");
valArray1.toString().replace("]", "");
int len = valArray1.length();
for (int i = 0; i < valArray1.length(); i++) {
Country country = new Country();
JSONObject arr = valArray1.getJSONObject(i);
country.setCountryCode(arr.getString("countryCode"));
country.setCountryName(arr.getString("countryName"));
arrCountries.add(country);
}
代码示例来源:origin: stackoverflow.com
JSONObject json = new JSONObject(jsonstring);
JSONArray nameArray = json.names();
JSONArray valArray = json.toJSONArray(nameArray);
JSONArray valArray1 = valArray.getJSONArray(1);
valArray1.toString().replace("[", "");
valArray1.toString().replace("]", "");
int len = valArray1.length();
for (int i = 0; i < valArray1.length(); i++) {
Country country = new Country();
JSONObject arr = valArray1.getJSONObject(i);
country.setCountryCode(arr.getString("countryCode"));
country.setCountryName(arr.getString("countryName"));
arrCountries.add(country);
}
代码示例来源:origin: stackoverflow.com
JSONObject json = new JSONObject(jsonstring);
JSONArray nameArray = json.names();
JSONArray valArray = json.toJSONArray(nameArray);
JSONArray valArray1 = valArray.getJSONArray(1);
valArray1.toString().replace("[", "");
valArray1.toString().replace("]", "");
int len = valArray1.length();
for (int i = 0; i < valArray1.length(); i++) {
Country country = new Country();
JSONObject arr = valArray1.getJSONObject(i);
country.setCountryCode(arr.getString("countryCode"));
country.setCountryName(arr.getString("countryName"));
arrCountries.add(country);
}
代码示例来源:origin: stackoverflow.com
JSONObject json = new JSONObject(jsonstring);
JSONArray nameArray = json.names();
JSONArray valArray = json.toJSONArray(nameArray);
JSONArray valArray1 = valArray.getJSONArray(1);
valArray1.toString().replace("[", "");
valArray1.toString().replace("]", "");
int len = valArray1.length();
for (int i = 0; i < valArray1.length(); i++) {
Country country = new Country();
JSONObject arr = valArray1.getJSONObject(i);
country.setCountryCode(arr.getString("countryCode"));
country.setCountryName(arr.getString("countryName"));
arrCountries.add(country);
}
代码示例来源:origin: stackoverflow.com
JSONObject json = new JSONObject(jsonstring);
JSONArray nameArray = json.names();
JSONArray valArray = json.toJSONArray(nameArray);
JSONArray valArray1 = valArray.getJSONArray(1);
valArray1.toString().replace("[", "");
valArray1.toString().replace("]", "");
int len = valArray1.length();
for (int i = 0; i < valArray1.length(); i++) {
Country country = new Country();
JSONObject arr = valArray1.getJSONObject(i);
country.setCountryCode(arr.getString("countryCode"));
country.setCountryName(arr.getString("countryName"));
arrCountries.add(country);
}
代码示例来源:origin: stackoverflow.com
JSONObject json = new JSONObject(jsonstring);
status = json.getString("result");
if (status.equalsIgnoreCase("success")) {
JSONArray nameArray = json.names();
JSONArray valArray = json.toJSONArray(nameArray);
JSONArray valArray1 = valArray.getJSONArray(1);
valArray1.toString().replace("[", "");
valArray1.toString().replace("]", "");
int len = valArray1.length();
for (int i = 0; i < valArray1.length(); i++) {
Country country = new Country();
JSONObject arr = valArray1.getJSONObject(i);
country.setCountryCode(arr.getString("countryCode"));
country.setCountryName(arr.getString("countryName"));
arrCountries.add(country);
}
}
内容来源于网络,如有侵权,请联系作者删除!