Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8961827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:58:56+00:00 2026-06-15T15:58:56+00:00

I’m trying to get some traffic data using the Bing Traffic API, but I

  • 0

I’m trying to get some traffic data using the Bing Traffic API, but I keep getting a JSONException.

The JSON is located HERE. I used a JSON formatter located here in order to better get an idea of the data that’s available to me. The url is publicly facing so I don’t know if I need to provide some sort of authentication data or not, because I can just plug the url into my browser and view the JSON result right there.

Here’s how I’m making the call

String url = "http://dev.virtualearth.net/REST/v1/Traffic/Incidents/37,-105,45,-94?key=" + API_KEY;

    // Create JSONParser instance
    JSONParser jParser = new JSONParser();

    // Get JSON from url
    final JSONObject jObject = jParser.getJSONFromUrl(url);


    try {
        JSONArray trafficData = jObject.getJSONObject(TAG_RESOURCESETS).getJSONArray(TAG_RESOURCES);
        Log.w("TrafficIncidentProvider", "Traffic Array consists of " + trafficData.toString());
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

I’m trying to get the object named “resourceSets” and the object named “resources”, since it seems that that’s where the data I need is embedded inside.. but obviously I’m going about it the wrong way because logCat is telling me that there’s no value that matches that data. Here’s the error logcat is giving me

  12-10 17:12:42.924: E/JSON Parser(26560): Error parsing data  org.json.JSONException:   End of input at character 0 of 
  12-10 17:12:42.944: W/System.err(26560): org.json.JSONException: No value for  resourceSets
  12-10 17:12:43.004: W/System.err(26560):  at org.json.JSONObject.get(JSONObject.java:354)
  12-10 17:12:43.004: W/System.err(26560):  at org.json.JSONObject.getJSONObject(JSONObject.java:569)
  12-10 17:12:43.014: W/System.err(26560):  at com.brightr.weathermate.providers.TrafficIncidentProvider.getTrafficIncidents(TrafficIncidentProvider.java:43)
  12-10 17:12:43.014: W/System.err(26560):  at com.brightr.weathermate.activities.LocationMapview$showTrafficConditions.doInBackground(LocationMapview.java:323)
  12-10 17:12:43.024: W/System.err(26560):  at com.brightr.weathermate.activities.LocationMapview$showTrafficConditions.doInBackground(LocationMapview.java:1)
  12-10 17:12:43.034: W/System.err(26560):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
  12-10 17:12:43.034: W/System.err(26560):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
  12-10 17:12:43.044: W/System.err(26560):  at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  12-10 17:12:43.044: W/System.err(26560):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
  12-10 17:12:43.044: W/System.err(26560):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)

Any clarity on this issue would be greatly appreciated, guys. Thanks as always!

EDIT: As requested, here is my JSONParser code which contains my HttpPost method

 public JSONObject getJSONFromUrl(String url) {

    // Making HTTP request
    try {
        // defaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);

        HttpResponse httpResponse = httpClient.execute(httpPost);


        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();          

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        json = sb.toString();
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    // try parsing the string to a JSON object
    try {
        if(json != null){
        jObj = new JSONObject(json);
        }else{
            jObj = null;
        }
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }

    // return JSON String
    return jObj;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:58:57+00:00Added an answer on June 15, 2026 at 3:58 pm

    Parse this json as:

             try {
                    JSONObject jobject=new JSONObject("Your_json_String");
                    JSONArray jarray=jobject.getJSONArray("resourceSets");
                      System.out.println("dateNow jarray :"+jarray.length());
                      for(int i=0;i<jarray.length();i++){
                          if(!jarray.isNull(i)){
                          JSONObject jobjresources=jarray.getJSONObject(i);
                          System.out.println("dateNow jobjresources :"+jobjresources.length());
                          //estimatedTotal
                          if(!jobjresources.isNull("estimatedTotal")){
                            String str_estimatedTotal=jobjresources.getString("estimatedTotal");
                            System.out.println("resources str_estimatedTotal :"+str_estimatedTotal);
    
                          }
                          else{
                              System.out.println("resources str_estimatedTotal NULL for :"+i+" ITEM");
                          }
                            if(!jobjresources.isNull("resources")){
                            //resources
                            JSONArray jarrresources=jobjresources.getJSONArray("resources");
                            for(int j=0;j<jarrresources.length();j++){
                                System.out.println("$$$$$$$$$$ ITEM "+j+" START $$$$$$$$$$$$$$$$#");
                                if(!jarrresources.isNull(j)){
    
                                JSONObject jobjjarrresources=jarrresources.getJSONObject(j);
                                if(!jobjjarrresources.isNull("__type")){
                                  //__type"
                                String str_type=jobjjarrresources.getString("__type");
                                System.out.println("resources str_type :"+str_type);
                                }
                                else{
                                    System.out.println("resources __type NULL for :"+j+" ITEM");
                                }
                                  //description"
                                if(!jobjjarrresources.isNull("description")){
                                String strdescription=jobjjarrresources.getString("description");
                                System.out.println("resources description :"+strdescription);
                                }
                                else{
                                    System.out.println("resources description NULL for :"+j+" ITEM");
                                }
                                  //lane"
                                if(!jobjjarrresources.isNull("lane")){
                                String strlane=jobjjarrresources.getString("lane");
                                System.out.println("resources lane :"+strlane);
                                }
                                else{
                                    System.out.println("resources lane NULL for :"+j+" ITEM");
                                }
                                  //lane"
                                if(!jobjjarrresources.isNull("point")){
                                    JSONObject jobjpoint=jobjjarrresources.getJSONObject("point");
                                    //point
                                    if(!jobjpoint.isNull("coordinates")){
                                    JSONArray jarcoordinates=jobjpoint.getJSONArray("coordinates");
                                    for(int k=0;k<jarcoordinates.length();k++){
                                        //JSONObject jobjcoordinates=jarcoordinates.getString(k);
                                         if(!jarcoordinates.isNull(k)){
                                        String str_zero=jarcoordinates.getString(k);
                                        System.out.println("coordinates :"+k+": "+str_zero);
                                         }
                                         else{
                                             System.out.println("coordinates :"+k+" is NULL:"+j+" ITEM");
                                         }
                                     }
                                    }
                                    else{
                                        System.out.println("resources coordinates NULL for :"+j+" ITEM");
                                    }
                                }
                                else{
                                    System.out.println("resources point NULL for :"+j+" ITEM");
                                }
    
                                  //roadClosed"
                                  //lane"
                                if(!jobjjarrresources.isNull("roadClosed")){
    
                                String strroadClosed=jobjjarrresources.getString("roadClosed");
                                System.out.println("resources roadClosed :"+strroadClosed);
                                }
                                else{
                                    System.out.println("resources roadClosed NULL for :"+j+" ITEM");
                                }
                                  //severity"
                                if(!jobjjarrresources.isNull("severity")){
                                String strroadseverity=jobjjarrresources.getString("severity");
                                System.out.println("resources severity :"+strroadseverity);
                                }
                                else
                                {
                                    System.out.println("resources severity NULL for :"+j+" ITEM");
                                }
                            }
                                else{
                                    System.out.println("jarrresources    NULL for :"+j+" ITEM");
                                }
    
                                System.out.println("##################### ITEM "+j+" END ##############");
                            }
                           }
                            else{
                                System.out.println("resources    NULL for :"+i+" ITEM");
                            }
                      }
    
                       else{
                           System.out.println("resources     NULL for : ITEM");
                          }  
              }
    
    
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I want to construct a data frame in an Rcpp function, but when I
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.