Hallo!
Ich habe von einer URL ein JSON das ich nach bestimmten Werten (eine bestimmte Tankstelle und der dazu gehörige Preis) filtern möchte. Die JSON sieht so aus:
[/B]
Mein Code sieht ca so aus:
Wie komme ich an die ID einer einzelnen Tankstelle und dem dazugehörigen Preis? Ich bekomme leider nur alle IDs ohne Preise auf einmal ausgegeben.
Ich habe von einer URL ein JSON das ich nach bestimmten Werten (eine bestimmte Tankstelle und der dazu gehörige Preis) filtern möchte. Die JSON sieht so aus:
JSON:
[
{
"id": 1473128, "name": "Diskont Tankstelle", "location": {
"address": "Wien Breitenfurter Strasse 261 (\"Hofer-Parkplatz\")", "postalCode": "1230", "city": "Wien", "latitude": 48.1506803, "longitude": 16.3016662
}, "contact": {
"telephone": "43800202055", "mail": "office@avanti.at", "website": [URL='http://www.diskonttanken.at/']"http://www.diskonttanken.at/"[/URL]
}, "openingHours": [
{
"day": "MO", "label": "Montag", "order": 1, "from": "00:00", "to": "24:00"
}, {
"day": "DI", "label": "Dienstag", "order": 2, "from": "00:00", "to": "24:00"
}, {
"day": "MI", "label": "Mittwoch", "order": 3, "from": "00:00", "to": "24:00"
}, {
"day": "DO", "label": "Donnerstag", "order": 4, "from": "00:00", "to": "24:00"
}, {
"day": "FR", "label": "Freitag", "order": 5, "from": "00:00", "to": "24:00"
}, {
"day": "SA", "label": "Samstag", "order": 6, "from": "00:00", "to": "24:00"
}, {
"day": "SO", "label": "Sonntag", "order": 7, "from": "00:00", "to": "24:00"
}, {
"day": "FE", "label": "Feiertag", "order": 8, "from": "00:00", "to": "24:00"
}
], "offerInformation": {
"service": false, "selfService": true, "unattended": true
}, "paymentMethods": {
"cash": false, "debitCard": true, "creditCard": true, "others": "DKV-Card"
}, "paymentArrangements": {
"cooperative": false, "clubCard": false
}, "position": 1, "open": true, "distance": 1.348419844455978, "prices": [
{
"fuelType": "SUP", "amount": 2.081, "label": "Super 95"
}
]
}, {
"id": 1354799, "name": "avanti - Vösendorf Schönbrunner Allee 20", "location": {
"address": "Schoenbrunner Allee 20", "postalCode": "2331", "city": "Voesendorf", "latitude": 48.13078, "longitude": 16.32632
}, "contact": {
"telephone": "800202055", "fax": "800", "website": "www.omv.com"
}, "openingHours": [
{
"day": "MO", "label": "Montag", "order": 1, "from": "00:00", "to": "24:00"
}, {
"day": "DI", "label": "Dienstag", "order": 2, "from": "00:00", "to": "24:00"
}, {
"day": "MI", "label": "Mittwoch", "order": 3, "from": "00:00", "to": "24:00"
}, {
"day": "DO", "label": "Donnerstag", "order": 4, "from": "00:00", "to": "24:00"
}, {
"day": "FR", "label": "Freitag", "order": 5, "from": "00:00", "to": "24:00"
}, {
"day": "SA", "label": "Samstag", "order": 6, "from": "00:00", "to": "24:00"
}, {
"day": "SO", "label": "Sonntag", "order": 7, "from": "00:00", "to": "24:00"
}, {
"day": "FE", "label": "Feiertag", "order": 8, "from": "00:00", "to": "24:00"
}
], "offerInformation": {
"service": false, "selfService": true, "unattended": true
}, "paymentMethods": {
"cash": false, "debitCard": true, "creditCard": true, "others": "OMV STATIONSKARTE, DKV, MASTERCARD, MAESTRO, ROUTEX, DINERS, VISA"
}, "paymentArrangements": {
"cooperative": false, "clubCard": false
}, "position": 2, "open": true, "distance": 2.215112887233922, "prices": [
{
"fuelType": "SUP", "amount": 2.084, "label": "Super 95"
}
]
}, {
"id": 1354941, "name": "avanti - Wien Edelsinnstraße 16", "location": {
"address": "Edelsinnstrasse 16", "postalCode": "1120", "city": "Wien", "latitude": 48.1724, "longitude": 16.31949
}, "contact": {
"telephone": "800202055", "fax": "800", "website": "www.omv.com"
}, "openingHours": [
{
"day": "MO", "label": "Montag", "order": 1, "from": "00:00", "to": "24:00"
}, {
"day": "DI", "label": "Dienstag", "order": 2, "from": "00:00", "to": "24:00"
}, {
"day": "MI", "label": "Mittwoch", "order": 3, "from": "00:00", "to": "24:00"
}, {
"day": "DO", "label": "Donnerstag", "order": 4, "from": "00:00", "to": "24:00"
}, {
"day": "FR", "label": "Freitag", "order": 5, "from": "00:00", "to": "24:00"
}, {
"day": "SA", "label": "Samstag", "order": 6, "from": "00:00", "to": "24:00"
}, {
"day": "SO", "label": "Sonntag", "order": 7, "from": "00:00", "to": "24:00"
}, {
"day": "FE", "label": "Feiertag", "order": 8, "from": "00:00", "to": "24:00"
}
], "offerInformation": {
"service": false, "selfService": true, "unattended": true
}, "paymentMethods": {
"cash": false, "debitCard": true, "creditCard": true, "others": "OMV STATIONSKARTE, DKV, MASTERCARD, MAESTRO, ROUTEX, DINERS, VISA"
}, "paymentArrangements": {
"cooperative": false, "clubCard": false
}, "position": 3, "open": true, "distance": 2.4707759804019376, "prices": [
{
"fuelType": "SUP", "amount": 2.089, "label": "Super 95"
}
]
}, {
"id": 334, "name": "OMV - Wien Sterngasse 13", "location": {
"address": "Sterngasse 13", "postalCode": "1230", "city": "Wien", "latitude": 48.14891, "longitude": 16.33836
}, "contact": {
"telephone": "16672130", "fax": "16672133", "mail": "retail.at.7666@omv.com", "website": "www.omv.com"
}, "openingHours": [
{
"day": "MO", "label": "Montag", "order": 1, "from": "00:00", "to": "24:00"
}, {
"day": "DI", "label": "Dienstag", "order": 2, "from": "00:00", "to": "24:00"
}, {
"day": "MI", "label": "Mittwoch", "order": 3, "from": "00:00", "to": "24:00"
}, {
"day": "DO", "label": "Donnerstag", "order": 4, "from": "00:00", "to": "24:00"
}, {
"day": "FR", "label": "Freitag", "order": 5, "from": "00:00", "to": "24:00"
}, {
"day": "SA", "label": "Samstag", "order": 6, "from": "00:00", "to": "24:00"
}, {
"day": "SO", "label": "Sonntag", "order": 7, "from": "00:00", "to": "24:00"
}, {
"day": "FE", "label": "Feiertag", "order": 8, "from": "00:00", "to": "24:00"
}
], "offerInformation": {
"service": true, "selfService": true, "unattended": false
}, "paymentMethods": {
"cash": true, "debitCard": true, "creditCard": true, "others": "OMV STATIONSKARTE, DKV, OMV ROUTEX, MASTERCARD, MAESTRO, ROUTEX, DINERS, VISA, AMEX"
}, "paymentArrangements": {
"cooperative": false, "clubCard": false
}, "position": 4, "open": true, "distance": 1.3853832878526326, "prices": [
{
"fuelType": "SUP", "amount": 2.119, "label": "Super 95"
}
]
}, {
"id": 35755, "name": "BP", "location": {
"address": "Triesterstrasse 104 ", "postalCode": "1100", "city": "Wien", "latitude": 48.15715224, "longitude": 16.34123557
}, "contact": {
"telephone": "4316674134", "fax": "431667413416", "mail": "R51876@bprosi.at"
}, "openingHours": [
{
"day": "MO", "label": "Montag", "order": 1, "from": "00:00", "to": "24:00"
}, {
"day": "DI", "label": "Dienstag", "order": 2, "from": "00:00", "to": "24:00"
}, {
"day": "MI", "label": "Mittwoch", "order": 3, "from": "00:00", "to": "24:00"
}, {
"day": "DO", "label": "Donnerstag", "order": 4, "from": "00:00", "to": "24:00"
}, {
"day": "FR", "label": "Freitag", "order": 5, "from": "00:00", "to": "24:00"
}, {
"day": "SA", "label": "Samstag", "order": 6, "from": "00:00", "to": "24:00"
}, {
"day": "SO", "label": "Sonntag", "order": 7, "from": "00:00", "to": "24:00"
}, {
"day": "FE", "label": "Feiertag", "order": 8, "from": "00:00", "to": "24:00"
}
], "offerInformation": {
"service": false, "selfService": true, "unattended": false
}, "paymentMethods": {
"cash": true, "debitCard": true, "creditCard": true, "others": "Routex"
}, "paymentArrangements": {
"cooperative": false, "clubCard": false
}, "otherServiceOffers": "WildBean Cafe Shop Car Wash Servicehalle Reifenservice", "position": 5, "open": true, "distance": 1.7694133390363103, "prices": [
{
"fuelType": "SUP", "amount": 2.119, "label": "Super 95"
}
]
}, {
"id": 35729, "name": "BP", "location": {
"address": "Triesterstrasse 153 ", "postalCode": "1100", "city": "Wien", "latitude": 48.15669974, "longitude": 16.34239786
}, "contact": {
"telephone": "4316167464", "fax": "431616746417", "mail": "R51308@bprosi.at"
}, "openingHours": [
{
"day": "MO", "label": "Montag", "order": 1, "from": "00:00", "to": "24:00"
}, {
"day": "DI", "label": "Dienstag", "order": 2, "from": "00:00", "to": "24:00"
}, {
"day": "MI", "label": "Mittwoch", "order": 3, "from": "00:00", "to": "24:00"
}, {
"day": "DO", "label": "Donnerstag", "order": 4, "from": "00:00", "to": "24:00"
}, {
"day": "FR", "label": "Freitag", "order": 5, "from": "00:00", "to": "24:00"
}, {
"day": "SA", "label": "Samstag", "order": 6, "from": "00:00", "to": "24:00"
}, {
"day": "SO", "label": "Sonntag", "order": 7, "from": "00:00", "to": "24:00"
}, {
"day": "FE", "label": "Feiertag", "order": 8, "from": "00:00", "to": "24:00"
}
], "offerInformation": {
"service": false, "selfService": true, "unattended": false
}, "paymentMethods": {
"cash": true, "debitCard": true, "creditCard": true, "others": "Routex"
}, "paymentArrangements": {
"cooperative": false, "clubCard": false
}, "otherServiceOffers": "WildBean Cafe Shop Car Wash", "position": 6, "open": true, "distance": 1.826920331191898, "prices": [
{
"fuelType": "SUP", "amount": 2.119, "label": "Super 95"
}
]
}, {
"id": 1354920, "name": "OMV - Wien Brunner Straße 77-79", "location": {
"address": "Brunner Strasse 77-79", "postalCode": "1230", "city": "Wien", "latitude": 48.13342, "longitude": 16.29849
}, "contact": {
"telephone": "18695856", "fax": "1869585613", "mail": "retail.at.7554@omv.com", "website": "www.omv.com"
}, "openingHours": [
{
"day": "MO", "label": "Montag", "order": 1, "from": "00:00", "to": "24:00"
}, {
"day": "DI", "label": "Dienstag", "order": 2, "from": "00:00", "to": "24:00"
}, {
"day": "MI", "label": "Mittwoch", "order": 3, "from": "00:00", "to": "24:00"
}, {
"day": "DO", "label": "Donnerstag", "order": 4, "from": "00:00", "to": "24:00"
}, {
"day": "FR", "label": "Freitag", "order": 5, "from": "00:00", "to": "24:00"
}, {
"day": "SA", "label": "Samstag", "order": 6, "from": "00:00", "to": "24:00"
}, {
"day": "SO", "label": "Sonntag", "order": 7, "from": "00:00", "to": "24:00"
}, {
"day": "FE", "label": "Feiertag", "order": 8, "from": "00:00", "to": "24:00"
}
], "offerInformation": {
"service": true, "selfService": true, "unattended": false
}, "paymentMethods": {
"cash": true, "debitCard": true, "creditCard": true, "others": "UTA, DKV, OMV ROUTEX, MASTERCARD, MAESTRO, ROUTEX, DINERS, VISA, AMEX, OMV STATIONSKARTE"
}, "paymentArrangements": {
"cooperative": false, "clubCard": false
}, "position": 7, "open": true, "distance": 2.4487309885142343, "prices": [
{
"fuelType": "SUP", "amount": 2.119, "label": "Super 95"
}
]
}, {
"id": 35686, "name": "BP", "location": {
"address": "Wienerbergstr. 29 ", "postalCode": "1120", "city": "Wien", "latitude": 48.170951, "longitude": 16.33682
}, "contact": {
"telephone": "4318156279", "fax": "43181562793", "mail": "R53132@bprosi.at"
}, "openingHours": [
{
"day": "MO", "label": "Montag", "order": 1, "from": "06:00", "to": "24:00"
}, {
"day": "DI", "label": "Dienstag", "order": 2, "from": "06:00", "to": "24:00"
}, {
"day": "MI", "label": "Mittwoch", "order": 3, "from": "06:00", "to": "24:00"
}, {
"day": "DO", "label": "Donnerstag", "order": 4, "from": "06:00", "to": "24:00"
}, {
"day": "FR", "label": "Freitag", "order": 5, "from": "06:00", "to": "24:00"
}, {
"day": "SA", "label": "Samstag", "order": 6, "from": "06:00", "to": "24:00"
}, {
"day": "SO", "label": "Sonntag", "order": 7, "from": "06:00", "to": "24:00"
}, {
"day": "FE", "label": "Feiertag", "order": 8, "from": "06:00", "to": "24:00"
}
], "offerInformation": {
"service": false, "selfService": true, "unattended": false
}, "paymentMethods": {
"cash": true, "debitCard": true, "creditCard": true, "others": "Routex"
}, "paymentArrangements": {
"cooperative": false, "clubCard": false
}, "otherServiceOffers": "Waschstrasse MO - SA von 7-19 Uhr und SO von 9-15 Uhr", "position": 8, "open": true, "distance": 2.6323166402600715, "prices": [
{
"fuelType": "SUP", "amount": 2.119, "label": "Super 95"
}
]
}, {
"id": 35768, "name": "BP", "location": {
"address": "Altmannsdorferstr.117 ", "postalCode": "1120", "city": "Wien", "latitude": 48.1609065, "longitude": 16.3184664
}, "contact": {
"telephone": "4316678737", "fax": "431667873713", "mail": "R51022@bprosi.at"
}, "openingHours": [
{
"day": "MO", "label": "Montag", "order": 1, "from": "00:00", "to": "24:00"
}, {
"day": "DI", "label": "Dienstag", "order": 2, "from": "00:00", "to": "24:00"
}, {
"day": "MI", "label": "Mittwoch", "order": 3, "from": "00:00", "to": "24:00"
}, {
"day": "DO", "label": "Donnerstag", "order": 4, "from": "00:00", "to": "24:00"
}, {
"day": "FR", "label": "Freitag", "order": 5, "from": "00:00", "to": "24:00"
}, {
"day": "SA", "label": "Samstag", "order": 6, "from": "00:00", "to": "24:00"
}, {
"day": "SO", "label": "Sonntag", "order": 7, "from": "00:00", "to": "24:00"
}, {
"day": "FE", "label": "Feiertag", "order": 8, "from": "00:00", "to": "24:00"
}
], "offerInformation": {
"service": false, "selfService": true, "unattended": false
}, "paymentMethods": {
"cash": true, "debitCard": true, "creditCard": true, "others": "Routex"
}, "paymentArrangements": {
"cooperative": false, "clubCard": false
}, "position": 9, "open": true, "distance": 1.195593315320322, "prices": []
}, {
"id": 35774, "name": "BP", "location": {
"address": "Altmannsdorferstr.94 ", "postalCode": "1120", "city": "Wien", "latitude": 48.1623607, "longitude": 16.3172305
}, "contact": {
"telephone": "4318043718", "fax": "43180437183", "mail": "R51840@bprosi.at"
}, "openingHours": [
{
"day": "MO", "label": "Montag", "order": 1, "from": "00:00", "to": "24:00"
}, {
"day": "DI", "label": "Dienstag", "order": 2, "from": "00:00", "to": "24:00"
}, {
"day": "MI", "label": "Mittwoch", "order": 3, "from": "00:00", "to": "24:00"
}, {
"day": "DO", "label": "Donnerstag", "order": 4, "from": "00:00", "to": "24:00"
}, {
"day": "FR", "label": "Freitag", "order": 5, "from": "00:00", "to": "24:00"
}, {
"day": "SA", "label": "Samstag", "order": 6, "from": "00:00", "to": "24:00"
}, {
"day": "SO", "label": "Sonntag", "order": 7, "from": "00:00", "to": "24:00"
}, {
"day": "FE", "label": "Feiertag", "order": 8, "from": "00:00", "to": "24:00"
}
], "offerInformation": {
"service": false, "selfService": true, "unattended": false
}, "paymentMethods": {
"cash": true, "debitCard": true, "creditCard": true, "others": "Routex"
}, "paymentArrangements": {
"cooperative": false, "clubCard": false
}, "position": 10, "open": true, "distance": 1.3667554599840392, "prices": []
}
]
[B]
Mein Code sieht ca so aus:
Java:
[/B]
import com.google.gson.Gson;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
public class Rechner {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Gson gson = new Gson();
JSON.Root[] id = null;
JSON.Price[] preis = null;
String address = "https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=48.150201766714105&longitude=16.319807691015892&fuelType=SUP&includeClosed=false";
URL url = new URL(address);
HttpURLConnection httpcon = (HttpURLConnection) url.openConnection();
//httpcon.addRequestProperty("User-Agent", "Mozilla/4.76");
InputStreamReader reader = new InputStreamReader(httpcon.getInputStream());
id = gson.fromJson(reader, JSON.Root[].class);
preis = gson.fromJson(reader, JSON.Price[].class);
for (JSON.Root diskont : id) {
System.out.println(diskont.id);
}
}
}
Java:
[/B]
import java.util.ArrayList;
public class JSON {
public class Contact{
public String telephone;
public String mail;
public String website;
public String fax;
}
public class Location{
public String address;
public String postalCode;
public String city;
public double latitude;
public double longitude;
}
public class OfferInformation{
public boolean service;
public boolean selfService;
public boolean unattended;
}
public class OpeningHour{
public String day;
public String label;
public int order;
public String from;
public String myto;
}
public class PaymentArrangements{
public boolean cooperative;
public boolean clubCard;
}
public class PaymentMethods{
public boolean cash;
public boolean debitCard;
public boolean creditCard;
public String others;
}
public class Price{
public String fuelType;
public double amount;
public String label;
}
public class Root{
public int id;
public String name;
public Location location;
public Contact contact;
public OfferInformation offerInformation;
public PaymentMethods paymentMethods;
public PaymentArrangements paymentArrangements;
public int position;
public boolean myopen;
public double distance;
public String otherServiceOffers;
public ArrayList<Price> prices;
}
}[B][/B]
Wie komme ich an die ID einer einzelnen Tankstelle und dem dazugehörigen Preis? Ich bekomme leider nur alle IDs ohne Preise auf einmal ausgegeben.