过去,我已经编写了JSON Java代码,该代码访问了现已失效的Pebble手表的数组,该手表访问了JSON文件。我现在正尝试在Java中为Netbeans中的另一个应用程序重新创建该代码,并想知道它们使用了哪个库,以简化代码设计。
我要直接使用的代码完全符合所需的密钥:
var daily_rain = json.agent.properties.dayRain.values[0].value;
我尝试使用Google的JSON Simple库,但是这种限定无效。我可以读取整个文件,但不能分离出数组,而无需迭代或更复杂的代码。
我希望有人可以识别该语法,并且知道哪个库使用该符号。
这是包含该行的Pebble js模块的代码:
function getWeather() {
var url = "http://www.wticalumni.com/DHK/Wxsnoop/weather.json";
// Send request to Weather
xhrRequest(url, 'GET',
function(responseText) {
// responseText contains a JSON object with weather info
var json = JSON.parse(responseText);
// console.log("ResponseText:" , responseText);
//Time
var time_from_json = json.time;
console.log("time from json = ", time_from_json);
//Outside Temp
var temperature_from_json = json.agent.properties.outdoorTemperature.values[0].value;
var temperature = RoundString(temperature_from_json);
console.log("outside temp from json = ", temperature, " rounded to ", temperature);
//Inside Temp
var temperature_inside_from_json = json.agent.properties.indoorTemperature.values[0].value;
var temperature_inside = RoundString(temperature_inside_from_json);
console.log("inside temp from json = ", temperature_inside_from_json, " rounded to ", temperature_inside);
//Daily Rain
var daily_rain = json.agent.properties.dayRain.values[0].value;
console.log("daily rain = ", daily_rain);
//Max Wind
var max_wind_from_json = json.agent.properties.windSpeed.maxValueToday.values[0].value;
var max_wind = RoundString(max_wind_from_json);
console.log("max wind from json = ", max_wind_from_json, " rounded to ", max_wind);
// Assemble dictionary using our keys
var dictionary = {
"TEMP_OUTSIDE": temperature,
"TEMP_INSIDE": temperature_inside,
"RAIN_DAILY": daily_rain,
"WIND_MAX": max_wind,
"TIME": time_from_json
};
// Send to Pebble
Pebble.sendAppMessage(dictionary,
function(e) {
console.log("Weather info sent to Pebble successfully!");
},
function(e) {
console.log("Error sending weather info to Pebble!");
}
);
} // End Function(responseText)
) ; // End xhrRequest
} // End getWeather