بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
مشکل در استفاده از json
سلام
من در قسمت یازده اموزش ها برای خوندن اطلاعات با json به مشکل برخوردم و هنگامی که میخوام یه مقدار بخونم خطا میده اینم کدم تو خط JSONObject object = new JSONObject(resaut); خطا میده
public class TestClientActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
HttpClient client = new DefaultHttpClient();
HttpPost method = new HttpPost("http://192.168.10.204/mysite/");
try {
HttpResponse response = client.execute(method);
int code = response.getStatusLine().getStatusCode();
Log.i("LOG", "Code: " + code);
InputStream stream = response.getEntity().getContent();
String resaut = convertStreamToString(stream);
JSONObject object = new JSONObject(resaut);
int hello = object.getInt("Hello");
}
catch (ClientProtocolException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String convertStreamToString(InputStream inputStream)
{
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder builder = new StringBuilder();
try {
String line;
while ((line = reader.readLine()) != null)
{
builder.append(line);
}
return builder.toString();
}
catch (IOException e) {
e.printStackTrace();
}
return "";
}
}
------------------------------------------------------------------------------------------------------
اینم کد php
------------------------------------------------------------------------------------------------------
<?php $array = array(); $array[] = 2; $array[] = 4; $array[] = 6; $array["Hello"] = 8; $array["Hello2"] = "Some String"; $anotherArray = array(); for($i=0;$i<10;$i++) { $anotherArray[] = $i; } $array["Another Array"] = array( "Tset1" => 1, "Test2" => "Hello", 3 => "Mt String", 4 => array( "a" => "abcd", "2" => "efgh", ), "ForLoop" => $anotherArray, ); echo json_encode($array); ?>
0
0
خطایی که میده چی هست، آیای قبل از اجرا خطا میگیره یا موقع اجرا؟ (10 سال پیش)
0
0
سلام
خطا چون توی try , catch هست بعد اجرا رخ میده ولی اگه نلاشه قبل اجرا قالبا باید رخ بده که امتحانش نکردم خطا از خط
JSONObject object = new JSONObject(resaut);
هستش و میگه که متغیر resault از فرمت jsonدرستی استفاده نمیکنه اما من کدهای استاد رو کپی کردم اما بازم همین خطارو میده و نمیدونم از چیه الان یک روز هست که درگیرش هستم
(10 سال پیش)
0
0
اگر میتونین کمکم کنید ممنون (10 سال پیش)
0
0
لینک (9 سال پیش)
برای این سوال پاسخی وجود ندارد.
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .