将数据解析为数组
好吧,面对这个问题,我无法将 try{} 内部的数据解析到外部的数据。 我在这里要完成的目标是什么...
for 循环将运行并向数组(图像)添加一个字符串(img)。 实际上它会将某些内容解析到数组中..但我无法将其放在数组之外 try/catch 块。有人可以帮我解决这个问题吗?
亲切的问候!
protected void onPostExecute(Void unused)
{
try
{
jArray = new JSONArray(result);
String[] image = new String[jArray.length()];
Log.v("Crash Detect", "onPostExecute -> try");
JSONObject json_data=null;
for(int i=0;i<jArray.length();i++)
{
Log.v("Crash Detect", "onPostExecute -> forloop");
json_data = jArray.getJSONObject(i);
merk=json_data.getString("printerMerk");
type=json_data.getString("printerType");
content = json_data.getString("content");
img = json_data.getString("Img");
Arrays.fill(image, img);
}
}
catch(JSONException e1)
{
Toast.makeText(getBaseContext(), "Niks gevonden" ,Toast.LENGTH_LONG).show();
}
catch (ParseException e1)
{
e1.printStackTrace();
}
dialog.dismiss();
Button home = (Button) findViewById(R.id.home);
Button printerType = (Button) findViewById(R.id.printerType);
home.setText(merk);
printerType.setText(type);
list=(ListView)findViewById(R.id.list);
adapter=new LazyAdapter(doc.this, image);
list.setAdapter(adapter);
}
Ok, facing the problem I can't parse my data from inside the try{} to something outside.
What is my goal to complete here...
The for-loop will run and add a string (img) to the array (image).
Actually it parses something to the array.. but I can't get it outside the
try/catch-block. Can somebody help me with this?
Kind regards!
protected void onPostExecute(Void unused)
{
try
{
jArray = new JSONArray(result);
String[] image = new String[jArray.length()];
Log.v("Crash Detect", "onPostExecute -> try");
JSONObject json_data=null;
for(int i=0;i<jArray.length();i++)
{
Log.v("Crash Detect", "onPostExecute -> forloop");
json_data = jArray.getJSONObject(i);
merk=json_data.getString("printerMerk");
type=json_data.getString("printerType");
content = json_data.getString("content");
img = json_data.getString("Img");
Arrays.fill(image, img);
}
}
catch(JSONException e1)
{
Toast.makeText(getBaseContext(), "Niks gevonden" ,Toast.LENGTH_LONG).show();
}
catch (ParseException e1)
{
e1.printStackTrace();
}
dialog.dismiss();
Button home = (Button) findViewById(R.id.home);
Button printerType = (Button) findViewById(R.id.printerType);
home.setText(merk);
printerType.setText(type);
list=(ListView)findViewById(R.id.list);
adapter=new LazyAdapter(doc.this, image);
list.setAdapter(adapter);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 try/catch 之外声明该变量,然后在要使用它时检查它是否已设置。
Declare the variable outside the try/catch and then check if it is set when you want to use it.
在 try catch 外部声明变量并将其设置在 try catch 内部。
然后你就可以在 try catch 之外访问它。
例如:
Declare your variable outside the try catch and set it inside the try catch.
Then you would be able to access it outside the try catch.
For instance: