mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-28 07:51:19 +02:00
Use parseJsonFromString() for parsing json data in
- CMoviePlayerGui::luaGetUrl() - CTimerList::RemoteBoxChanExists() - CTimerList::RemoteBoxTimerList() - CTimerList::paintItem() - cTmdb::GetMovieDetails() - cYTFeedParser::parseFeedJSON() - cYTFeedParser::parseFeedDetailsJSON()
This commit is contained in:
@@ -59,6 +59,7 @@
|
|||||||
#include <driver/fontrenderer.h>
|
#include <driver/fontrenderer.h>
|
||||||
#include <eitd/edvbstring.h>
|
#include <eitd/edvbstring.h>
|
||||||
#include <system/helpers.h>
|
#include <system/helpers.h>
|
||||||
|
#include <system/helpers-json.h>
|
||||||
|
|
||||||
#include <src/mymenu.h>
|
#include <src/mymenu.h>
|
||||||
|
|
||||||
@@ -814,12 +815,12 @@ bool CMoviePlayerGui::luaGetUrl(const std::string &script, const std::string &fi
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string errMsg = "";
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
Json::Reader reader;
|
bool ok = parseJsonFromString(result_string, &root, &errMsg);
|
||||||
bool parsedSuccess = reader.parse(result_string, root, false);
|
if (!ok) {
|
||||||
if (!parsedSuccess) {
|
|
||||||
printf("Failed to parse JSON\n");
|
printf("Failed to parse JSON\n");
|
||||||
printf("%s\n", reader.getFormattedErrorMessages().c_str());
|
printf("%s\n", errMsg.c_str());
|
||||||
if (box != NULL) {
|
if (box != NULL) {
|
||||||
box->hide();
|
box->hide();
|
||||||
delete box;
|
delete box;
|
||||||
|
@@ -69,6 +69,7 @@
|
|||||||
#include <system/settings.h>
|
#include <system/settings.h>
|
||||||
#include <system/fsmounter.h>
|
#include <system/fsmounter.h>
|
||||||
#include <system/helpers.h>
|
#include <system/helpers.h>
|
||||||
|
#include <system/helpers-json.h>
|
||||||
#include <system/httptool.h>
|
#include <system/httptool.h>
|
||||||
|
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
@@ -738,16 +739,15 @@ bool CTimerList::RemoteBoxChanExists(t_channel_id channel_id)
|
|||||||
r_url += string_printf_helper(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, channel_id);
|
r_url += string_printf_helper(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, channel_id);
|
||||||
r_url = httpTool.downloadString(r_url, -1, httpConnectTimeout);
|
r_url = httpTool.downloadString(r_url, -1, httpConnectTimeout);
|
||||||
|
|
||||||
|
string errMsg = "";
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
Json::Reader reader;
|
bool ok = parseJsonFromString(r_url, &root, &errMsg);
|
||||||
bool parsedSuccess = reader.parse(r_url, root, false);
|
if (!ok) {
|
||||||
if (!parsedSuccess) {
|
|
||||||
printf("Failed to parse JSON\n");
|
printf("Failed to parse JSON\n");
|
||||||
printf("%s\n", reader.getFormattedErrorMessages().c_str());
|
printf("%s\n", errMsg.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
r_url = root.get("success","false").asString();
|
r_url = root.get("success","false").asString();
|
||||||
|
|
||||||
if (r_url == "false")
|
if (r_url == "false")
|
||||||
ShowMsg(LOCALE_REMOTEBOX_CHANNEL_NA, convertChannelId2String(channel_id),
|
ShowMsg(LOCALE_REMOTEBOX_CHANNEL_NA, convertChannelId2String(channel_id),
|
||||||
CMsgBox::mbrOk, CMsgBox::mbOk, NULL, 450, 30, false);
|
CMsgBox::mbrOk, CMsgBox::mbOk, NULL, 450, 30, false);
|
||||||
@@ -796,13 +796,12 @@ void CTimerList::RemoteBoxTimerList(CTimerd::TimerList &rtimerlist)
|
|||||||
r_url = httpTool.downloadString(r_url, -1, httpConnectTimeout);
|
r_url = httpTool.downloadString(r_url, -1, httpConnectTimeout);
|
||||||
//printf("[remotetimer] timers:%s\n",r_url.c_str());
|
//printf("[remotetimer] timers:%s\n",r_url.c_str());
|
||||||
|
|
||||||
|
string errMsg = "";
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
Json::Reader reader;
|
bool ok = parseJsonFromString(r_url, &root, &errMsg);
|
||||||
bool parsedSuccess = reader.parse(r_url, root, false);
|
if (!ok) {
|
||||||
if (!parsedSuccess)
|
|
||||||
{
|
|
||||||
printf("Failed to parse JSON\n");
|
printf("Failed to parse JSON\n");
|
||||||
printf("%s\n", reader.getFormattedErrorMessages().c_str());
|
printf("%s\n", errMsg.c_str());
|
||||||
it->online = false;
|
it->online = false;
|
||||||
} else
|
} else
|
||||||
it->online = true;
|
it->online = true;
|
||||||
@@ -1286,13 +1285,12 @@ void CTimerList::paintItem(int pos)
|
|||||||
r_url += string_printf_helper(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, timer.channel_id);
|
r_url += string_printf_helper(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, timer.channel_id);
|
||||||
r_url = httpTool.downloadString(r_url, -1, httpConnectTimeout);
|
r_url = httpTool.downloadString(r_url, -1, httpConnectTimeout);
|
||||||
|
|
||||||
|
string errMsg = "";
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
Json::Reader reader;
|
bool ok = parseJsonFromString(r_url, &root, &errMsg);
|
||||||
bool parsedSuccess = reader.parse(r_url, root, false);
|
if (!ok) {
|
||||||
if (!parsedSuccess)
|
|
||||||
{
|
|
||||||
printf("Failed to parse JSON\n");
|
printf("Failed to parse JSON\n");
|
||||||
printf("%s\n", reader.getFormattedErrorMessages().c_str());
|
printf("%s\n", errMsg.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value remotechannel = root["data"]["channel"][0];
|
Json::Value remotechannel = root["data"]["channel"][0];
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#include "system/settings.h"
|
#include "system/settings.h"
|
||||||
#include "system/helpers.h"
|
#include "system/helpers.h"
|
||||||
|
#include <system/helpers-json.h>
|
||||||
#include "system/set_threadname.h"
|
#include "system/set_threadname.h"
|
||||||
#include "gui/widget/hintbox.h"
|
#include "gui/widget/hintbox.h"
|
||||||
|
|
||||||
@@ -197,12 +198,12 @@ bool cTmdb::GetMovieDetails(std::string lang)
|
|||||||
if (!getUrl(url, answer))
|
if (!getUrl(url, answer))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
string errMsg = "";
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
Json::Reader reader;
|
bool ok = parseJsonFromString(answer, &root, &errMsg);
|
||||||
bool parsedSuccess = reader.parse(answer, root, false);
|
if (!ok) {
|
||||||
if (!parsedSuccess) {
|
|
||||||
printf("Failed to parse JSON\n");
|
printf("Failed to parse JSON\n");
|
||||||
printf("%s\n", reader.getFormattedErrorMessages().c_str());
|
printf("%s\n", errMsg.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,10 +220,11 @@ bool cTmdb::GetMovieDetails(std::string lang)
|
|||||||
answer.clear();
|
answer.clear();
|
||||||
if (!getUrl(url, answer))
|
if (!getUrl(url, answer))
|
||||||
return false;
|
return false;
|
||||||
parsedSuccess = reader.parse(answer, root, false);
|
|
||||||
if (!parsedSuccess) {
|
ok = parseJsonFromString(answer, &root, &errMsg);
|
||||||
|
if (!ok) {
|
||||||
printf("Failed to parse JSON\n");
|
printf("Failed to parse JSON\n");
|
||||||
printf("%s\n", reader.getFormattedErrorMessages().c_str());
|
printf("%s\n", errMsg.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,6 +38,7 @@
|
|||||||
#include <OpenThreads/ScopedLock>
|
#include <OpenThreads/ScopedLock>
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
#include "helpers-json.h"
|
||||||
#include "set_threadname.h"
|
#include "set_threadname.h"
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
@@ -288,25 +289,25 @@ std::string cYTFeedParser::getXmlData(xmlNodePtr node)
|
|||||||
|
|
||||||
bool cYTFeedParser::parseFeedJSON(std::string &answer)
|
bool cYTFeedParser::parseFeedJSON(std::string &answer)
|
||||||
{
|
{
|
||||||
|
string errMsg = "";
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
Json::Reader reader;
|
|
||||||
|
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
std::ifstream fh(curfeedfile.c_str(),std::ifstream::in);
|
std::ifstream fh(curfeedfile.c_str(),std::ifstream::in);
|
||||||
ss << fh.rdbuf();
|
ss << fh.rdbuf();
|
||||||
std::string filedata = ss.str();
|
std::string filedata = ss.str();
|
||||||
|
|
||||||
bool parsedSuccess = reader.parse(filedata,root,false);
|
bool parsedSuccess = parseJsonFromString(filedata, &root, NULL);
|
||||||
|
|
||||||
if(!parsedSuccess)
|
if(!parsedSuccess)
|
||||||
{
|
{
|
||||||
parsedSuccess = reader.parse(answer,root,false);
|
parsedSuccess = parseJsonFromString(answer, &root, &errMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!parsedSuccess)
|
if(!parsedSuccess)
|
||||||
{
|
{
|
||||||
printf("Failed to parse JSON\n");
|
printf("Failed to parse JSON\n");
|
||||||
printf("%s\n", reader.getFormattedErrorMessages().c_str());
|
printf("%s\n", errMsg.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,15 +384,16 @@ bool cYTFeedParser::parseFeedDetailsJSON(cYTVideoInfo* vinfo)
|
|||||||
if (!getUrl(url, answer))
|
if (!getUrl(url, answer))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
string errMsg = "";
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
Json::Reader reader;
|
bool parsedSuccess = parseJsonFromString(answer, &root, &errMsg);
|
||||||
bool parsedSuccess = reader.parse(answer, root, false);
|
|
||||||
if (!parsedSuccess) {
|
if (!parsedSuccess) {
|
||||||
printf("Failed to parse JSON\n");
|
printf("Failed to parse JSON\n");
|
||||||
printf("%s\n", reader.getFormattedErrorMessages().c_str());
|
printf("%s\n", errMsg.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Json::Value elements = root["items"];
|
Json::Value elements = root["items"];
|
||||||
std::string duration = elements[0]["contentDetails"].get("duration", "").asString();
|
std::string duration = elements[0]["contentDetails"].get("duration", "").asString();
|
||||||
if (duration.find("PT") != std::string::npos) {
|
if (duration.find("PT") != std::string::npos) {
|
||||||
|
Reference in New Issue
Block a user