【发布时间】:2018-12-11 05:03:40
【问题描述】:
我有这样的程序
String[] hello; Integer[] yAxisData2;
我想将字符串 json 数组转换为 int 数组。 , 如何将字符串 hello[i] 转换为 int 数组?
private void generateY(){
mApiInterface.getGulaDarah(idUser).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if(response.isSuccessful()){
try{
JSONArray jsonRes = new JSONArray(response.body().string());
hello = new String[jsonRes.length()];
for(int i=0; i<jsonRes.length(); i++){
JSONObject jsonObject = jsonRes.getJSONObject(i);
hello[i] =jsonObject.getString("guladarah_acak");
yAxisData2[]=Integer.parseInt(hello[i]);
}
}catch (JSONException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
}
});
}
【问题讨论】:
-
"guladarah_acak" 这是什么结构......
-
请发布json的结构。如果“guladarah_acak”是字符串并且您需要将其转换为
int,您可以使用parseInt(),但您需要初始化yAxisData2,就像您使用它的大小初始化hello一样,然后您可以使用索引分配一个值。