Ben php/json içinde bir web hizmetleri etrafında uğraş veriyorum.PHP Web Hizmeti JSON Kodlama
<?php
$answer = array('status'=>401, 'answer'=>'');
if($numWeeks%2 == 0) {
$answer['answer'] = 'trash';
utf8_encode($answer['answer']);
$answer['status'] = 200;
}
else {
$answer['answer'] = 'trach/recycle';
utf8_encode($answer['answer']);
$answer['status'] = 200;
}
header('Content-type: application/json');
echo json_encode($answer);
?>
çıkışı:
{"status":200,"answer":"trash"}
Ben de RETROFIT (v1.9) kullanılarak bir android uygulaması ile bu okumaya çalışıyorum.
Benim nesne sınıfıdır:
public class TrashResponse {
public int status;
public String answer;
}
Ama bu hatayı alıyorum: benim web hizmetinden benim json nesnesi ile ilgisi var Benim araştırma
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
. Sorunun ne olduğuna işaret edemem.
işe yaramadı :(hala aynı hatayı alıyorum ... int türünü değiştirdim ve çalışmaz –
jy kodlama UTF8 olmama ile ilgili olduğunu düşünüyor musunuz? –