cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Unable To Convert From java.lang.String to INFOTABLE

rsaxena1
1-Newbie

Unable To Convert From java.lang.String to INFOTABLE

Hi all,

I'm receiving the error Unable To Convert From java.lang.String to INFOTABLE when i'm using the webservice to get the weather data in my thing.

This is the webservice i've used.

var LocationIn=location+" ";

//var arrayLocations=stringLocation.split(",");

//var lat=arrayLocations[0];

//var long=arrayLocations[1];

var apiKey = "Placed my api key here";

var temperature;

var humidity;

//Inputted location needs to be valid lat, long: 40.7127, 74.0059

if(LocationIn != null){

    var test = LocationIn + " ";

    var arrayLocations = test.split(",");

    var lat = arrayLocations[0];

    var long = arrayLocations[1];

    var prm = {

        url: "http://api.wunderground.com/api/"+apiKey+"/conditions/q/"+lat+","+long+".json",

        timeout: 60

    };

    var json = Resources["ContentLoaderFunctions"].PostJSON(prm);

         

    try {

        temperature = parseInt(json.current_observation.temp_f);

        humidity = parseInt(json.current_observation.relative_humidity);

        me.Temperature = temperature;

        me.Humidity = humidity;

        result = "Success. Properties are updated.";

    } catch(err) {

        logger.error("Could not parse temperature and humidity for location: " + LocationIn

          + ". All valid Longitudes and Latitudes values must have decimal points"                      + " and be located where weather measurements are commonly taken (near cities).");

        result = "Failed. Check Script Logs";

    }

}

When I'm hitting the url directly, I'm getting the response but i'm unable to get the response through the webservice in my thing.

The following are the fields i've used in the service for my thing

Name = “Link”, Base Type = HYPERLINK

Name = “Title”, Base Type = STRING;

Name = “WeatherCondition”, Base Type = IMAGELINK;

Name = “WeatherTemp”, Base Type = Number;

Name = “WeatherHumidity”, Base Type = Number;

Name = “WindSpeed”, Base Type = STRING;

Name = “WindDirection”, Base Type = STRING;

Name = “Sunrise”, Base Type = STRING;

Name = “Sunset”, Base Type = STRING;

Name = “City”, Base Type = STRING;

the below is a sample response when you hit the URL directly:

{

  "response": {

  "version":"0.1",

  "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",

  "features": {

  "conditions": 1

  }

}

  , "current_observation": {

"image": {

"url":"http://icons.wxug.com/graphics/wu2/logo_130x80.png",

"title":"Weather Underground",

"link":"http://www.wunderground.com"

},

"display_location": {

"full":"Gurgaon, India",

"city":"Gurgaon",

"state":"HR",

"state_name":"India",

"country":"IN",

"country_iso3166":"IN",

"zip":"00000",

"magic":"41",

"wmo":"42178",

"latitude":"28.450000",

"longitude":"77.020000",

"elevation":"225.9"

},

"observation_location": {

"full":"New Delhi, ",

"city":"New Delhi",

"state":"",

"country":"IN",

"country_iso3166":"IN",

"latitude":"28.56666756",

"longitude":"77.11666870",

"elevation":"764 ft"

},

"estimated": {

},

"station_id":"VIDP",

"observation_time":"Last Updated on December 15, 2:00 PM IST",

"observation_time_rfc822":"Thu, 15 Dec 2016 14:00:00 +0530",

"observation_epoch":"1481790600",

"local_time_rfc822":"Thu, 15 Dec 2016 14:29:06 +0530",

"local_epoch":"1481792346",

"local_tz_short":"IST",

"local_tz_long":"Asia/Kolkata",

"local_tz_offset":"+0530",

"weather":"Haze",

"temperature_string":"73 F (23 C)",

"temp_f":73,

"temp_c":23,

"relative_humidity":"38%",

"wind_string":"From the WNW at 7 MPH Gusting to 18 MPH",

"wind_dir":"WNW",

"wind_degrees":300,

"wind_mph":7,

"wind_gust_mph":"18",

"wind_kph":11,

"wind_gust_kph":"30",

"pressure_mb":"1016",

"pressure_in":"30.01",

"pressure_trend":"-",

"dewpoint_string":"46 F (8 C)",

"dewpoint_f":46,

"dewpoint_c":8,

"heat_index_string":"NA",

"heat_index_f":"NA",

"heat_index_c":"NA",

"windchill_string":"NA",

"windchill_f":"NA",

"windchill_c":"NA",

"feelslike_string":"73 F (23 C)",

"feelslike_f":"73",

"feelslike_c":"23",

"visibility_mi":"1.7",

"visibility_km":"2.8",

"solarradiation":"--",

"UV":"-1","precip_1hr_string":"-9999.00 in (-9999.00 mm)",

"precip_1hr_in":"-9999.00",

"precip_1hr_metric":"--",

"precip_today_string":"0.00 in (0.0 mm)",

"precip_today_in":"0.00",

"precip_today_metric":"0.0",

"icon":"hazy",

"icon_url":"http://icons.wxug.com/i/c/k/hazy.gif",

"forecast_url":"http://www.wunderground.com/global/stations/42178.html",

"history_url":"http://www.wunderground.com/history/airport/VIDP/2016/12/15/DailyHistory.html",

"ob_url":"http://www.wunderground.com/cgi-bin/findweather/getForecast?query=28.56666756,77.11666870",

"nowcast":""

}

}

can you tell me how to get the data into thingworx and why i'm receiving this error and how to resolve it ?

Thanking you




Message was edited by: Polina Osipova

3 REPLIES 3
Aanjan
9-Granite
(To:rsaxena1)

Rajat, is your service output set to INFOTABLE? If so, change it to STRING, as your results seem to be printing out strings.

Assuming that Aanjan is correct and that the output of your service is an InfoTable, this error makes sense.  ThingWorx will try to do the some conversions for you behind the scenes and is pretty resilient most of the time - however, for the INFOTABLE type, there is some additional definition that is needed to do the conversion which is the DataShape definition for the InfoTable and the data in a 'rows' array.

The InfoTable type is best kept for services from ThingWorx to other ThingWorx APIs as the InfoTable standard is proprietary to ThingWorx.  So, Like Aanjan said, you should probably change the output type of your service, but I think that (based on the output you pasted in your question) the JSON type will be more fitting, and I predict the 'conversion' from string to JSON will go much more smoothly than the string to InfoTable conversion being done now.

sbalta
12-Amethyst
(To:rsaxena1)

What is the service that you use to view these data?

Top Tags