Autore Topic: Chiarimento JSON  (Letto 546 volte)

Offline Elmvor

  • Utente normale
  • ***
  • Post: 166
  • Respect: 0
    • Mostra profilo
  • Sistema operativo:
    Ubuntu 14.04, Windows 8.1
Chiarimento JSON
« il: 12 Febbraio 2014, 11:53:13 CET »
0
Il JSON relativo al percorso tra vari punti contiene una parte tipo questa:
Codice: [Seleziona]
"legs":[{"duration":{"value":628,"text":"10 mins"},"distance":{"value":876,"text":"0.9 km"}...
Vorrei essere sicuro di cosa indica. Duration e' il tempo di percorrenza relativo al mezzo di trasporto che ho scelto quando ho fatto la richiesta? In questo caso sarebbero 10 minuti a piedi? Distance è la lunghezza del percorso che ho calcolato?

Se volessi estrarre queste informazioni dal JSON come devo fare? Grazie

Offline ciccio

  • Utente junior
  • **
  • Post: 65
  • Respect: +7
    • Mostra profilo
  • Dispositivo Android:
    Nexus 5
  • Play Store ID:
    Francesco Cervone
  • Sistema operativo:
    Mac OS X 10.9
Re:Chiarimento JSON
« Risposta #1 il: 12 Febbraio 2014, 15:22:50 CET »
+1
Non possiamo saperlo se non ci dici di cosa si tratta, quale web service stai usando, una pagina web che spiega nel dettaglio tutti i campi del servizio (che potresti consultare tu stesso).
Se hai dubbi sul formato JSON questo potrebbe tornarti utile: http://www.json.org/

Post unito: 12 Febbraio 2014, 15:23:51 CET
Inoltre in android c'è questo package per prelevare tutti i dati che vuoi da documenti JSON: http://developer.android.com/reference/org/json/package-summary.html

Offline Nicola_D

  • Moderatore
  • Utente storico
  • *****
  • Post: 2479
  • SBAGLIATO!
  • Respect: +323
    • Github
    • Google+
    • nicoladorigatti
    • Mostra profilo
  • Dispositivo Android:
    Nexus 6p, Nexus 4, Nexus S, Nexus 7(2012)
  • Sistema operativo:
    Windows 7
Re:Chiarimento JSON
« Risposta #2 il: 12 Febbraio 2014, 16:20:05 CET »
+1
come nell'altro post, ti invito a leggere la documentazione delle directions api se non le conosci:
https://developers.google.com/maps/documentation/directions/
Citazione
Routes

When the Directions API returns results, it places them within a (JSON) routes array. Even if the service returns no results (such as if the origin and/or destination doesn't exist) it still returns an empty routes array. (XML responses consist of zero or more <route> elements.)

Each element of the routes array contains a single result from the specified origin and destination. This route may consist of one or more legs depending on whether any waypoints were specified. As well, the route also contains copyright and warning information which must be displayed to the user in addition to the routing information.

Each route within the routes field may contain the following fields:

summary contains a short textual description for the route, suitable for naming and disambiguating the route from alternatives.
legs[] contains an array which contains information about a leg of the route, between two locations within the given route. A separate leg will be present for each waypoint or destination specified. (A route with no waypoints will contain exactly one leg within the legs array.) Each leg consists of a series of steps. (See Directions Legs below.)
waypoint_order contains an array indicating the order of any waypoints in the calculated route. This waypoints may be reordered if the request was passed optimize:true within its waypoints parameter.
overview_polyline contains an object holding an array of encoded points that represent an approximate (smoothed) path of the resulting directions.
bounds contains the viewport bounding box of the overview_polyline.
copyrights contains the copyrights text to be displayed for this route. You must handle and display this information yourself.
warnings[] contains an array of warnings to be displayed when showing these directions. You must handle and display these warnings yourself.
Legs

Each element in the legs array specifies a single leg of the journey from the origin to the destination in the calculated route. For routes that contain no waypoints, the route will consist of a single "leg," but for routes that define one or more waypoints, the route will consist of one or more legs, corresponding to the specific legs of the journey.

Each leg within the legs field(s) may contain the following fields:

steps[] contains an array of steps denoting information about each separate step of the leg of the journey. (See Directions Steps below.)
distance indicates the total distance covered by this leg, as a field with the following elements:

value indicates the distance in meters
text contains a human-readable representation of the distance, displayed in units as used at the origin (or as overridden within the units parameter in the request). (For example, miles and feet will be used for any origin within the United States.) Note that regardless of what unit system is displayed as text, the distance.value field always contains a value expressed in meters.
These fields may be absent if the distance is unknown.


duration indicates the total duration of this leg, as a field with the following elements:

value indicates the duration in seconds.
text contains a human-readable representation of the duration.
These fields may be absent if the duration is unknown.


duration_in_traffic indicates the total duration of this leg, taking into account current traffic conditions. The duration in traffic will only be returned if all of the following are true:

The directions request includes a departure_time parameter set to a value within a few minutes of the current time.
The request includes a valid Maps for Business client and signature parameter.
Traffic conditions are available for the requested route.
The directions request does not include stopover waypoints.
The duration_in_traffic will contain the following fields:

value indicates the duration in seconds.
text contains a human-readable representation of the duration.
IMPORTANTE:NON RISPONDO A PROBLEMI VIA MESSAGGIO PRIVATO
LOGCAT: Non sai cos'è? -> Android Debug Bridge | Android Developers
               Dov'è in Eclipse? -> Window -> Open Prospective -> DDMS e guarda in basso!
[Obbligatorio] Logcat, questo sconosciuto! (Gruppo AndDev.it LOGTFO) - Android Developers Italia

iClaude

  • Visitatore
Re:Chiarimento JSON
« Risposta #3 il: 13 Febbraio 2014, 13:01:04 CET »
0
A me sembra abbastanza chiaro: value è il valore esatto in secondi/metri e text è un testo esplicativo usato  probabilmente x la visualizzazione.

Offline Elmvor

  • Utente normale
  • ***
  • Post: 166
  • Respect: 0
    • Mostra profilo
  • Sistema operativo:
    Ubuntu 14.04, Windows 8.1
Re:Chiarimento JSON
« Risposta #4 il: 13 Febbraio 2014, 19:31:20 CET »
0
Ho risolto. Era piuttosto semplice. Ho approfondito un po la struttura dei JSON ed ho capito :) Se volete metto il poco codice che serviva...