я произвожу JSON как это:Я не могу прочитать данные из JSON
[ "\" Latitud \ ": \" 123,0 \», \ "Orden \": \ "0 \", \ "LONGITUD \": \ "123,0 \", \ "urlfoto \": \ "а \", \ "idruta \": \ "45 \"}», "{\" Latitud \ ": \" 321,0 \ », \ "Orden \": \ "1 \", \ "LONGITUD \": \ "321,0 \", \ "urlfoto \": \ "Ъ \", \ "idruta \": \ "45 \"} " "{\" Latitud \ ": \" 231,0 \", \ "Orden \": \ "2 \", \ "LONGITUD \": \ "231,0 \", \ "urlfoto \": \ "С \ "\ "idruta \": \ "45 \"}"]
Я ищу здесь, и я судимый:
$puntos = $_POST['puntos'];
$data = json_decode($puntos,true);
foreach($data as $obj) {
$idruta = $obj['idruta'];
$orden = $obj['orden'];
$urlfoto = $obj['urlfoto'];
$longitud = $obj['longitud'];
$latitud = $obj['latitud'];
}
Illegal строка Смещение 'idruta'
foreach($data as $obj) {
$idruta = $obj->idruta;
$orden = $obj->orden;
$urlfoto = $obj->urlfoto;
$longitud = $obj->longitud;
$latitud = $obj->latitud;
}
Попытка получить свойство необъектных
foreach($data as $obj) {
$idruta = $obj[0];
$orden = $obj[1];
$urlfoto = $obj[2];
$longitud = $obj[3];
$latitud = $obj[4];
}
OBJ [я] всегда 0 и нет ошибок.
Цикл делает 3 раза, так что все в порядке.
Извините, я просто изучаю JSON и php, я буду очень рад, если кто-нибудь может помочь мне получить данные JSON.
Спасибо!
EDIT: Спасибо за ответы! Я не знаю, почему отсутствует «{», и когда я вставляю тот же json в JSONlint, например, его проверки корректны, поэтому ... Я немного потерял извинения.
Вот так я посылаю JSON:
public void insertPoints(ArrayList<Punto> puntos){
JSONArray array = new JSONArray();
List<NameValuePair> params = new ArrayList<NameValuePair>();
for(Punto p:puntos){
JSONObject obj = new JSONObject();
try {
obj.put("idruta",Integer.toString(p.getIdruta()));
obj.put("orden",Integer.toString(p.getOrden()));
obj.put("urlfoto",p.getUrlfoto());
obj.put("longitud",Double.toString(p.getLongitud()));
obj.put("latitud",Double.toString(p.getLongitud()));
array.put(obj.toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost request = new HttpPost(CREATE_POINT);
StringEntity params =new StringEntity("puntos=" + postjson);
request.addHeader("content-type", "application/x-www-form-urlencoded");
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
// handle response here...
} catch (Exception ex) {
// handle exception here
} finally {
httpClient.getConnectionManager().shutdown();
}
}
здесь какие-либо проблемы?
Спасибо!
нет открывающей скобки для первого закрывающего –
Вам не хватает '{' после вашего первого '['. –
Не должно быть никаких '\\'. –