Skip to content

Commit dadc9ed

Browse files
committed
ofJson
1 parent d29ca9a commit dadc9ed

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

libs/ofxLibwebsockets/include/ofxLibwebsockets/Events.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace ofxLibwebsockets {
2020

2121
Connection& conn;
2222
std::string message; // message from ws OR error message if error
23-
Json::Value json;
23+
ofJson json;
2424

2525
// binary data
2626
bool isBinary;
@@ -36,4 +36,4 @@ namespace ofxLibwebsockets {
3636
ofEvent<ofxLibwebsockets::Event> onClose;
3737
ofEvent<ofxLibwebsockets::Event> onIdle;
3838
ofEvent<ofxLibwebsockets::Event> onMessage;
39-
};*/
39+
};*/

libs/ofxLibwebsockets/include/ofxLibwebsockets/Protocol.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ namespace ofxLibwebsockets {
1919

2020
class Reactor;
2121

22-
#include "json.h"
23-
2422
class Protocol
2523
{
2624
friend class Reactor;
@@ -76,4 +74,4 @@ namespace ofxLibwebsockets {
7674
bool _allowClient(const std::string name,
7775
const std::string ip) const;
7876
};
79-
};
77+
};

libs/ofxLibwebsockets/include/ofxLibwebsockets/Reactor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ namespace ofxLibwebsockets {
7575
// maybe this should be a map?
7676
vector<Connection *> connections;
7777

78-
private:
79-
Json::Reader reader;
8078

8179
};
8280

libs/ofxLibwebsockets/src/Reactor.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,18 @@ namespace ofxLibwebsockets {
251251
}
252252

253253
if (_message != NULL && len > 0 && (!bReceivingLargeMessage || bFinishedReceiving) ){
254-
args.json = Json::Value( Json::nullValue );
255254

256-
bool parsingSuccessful = ( bParseJSON ? reader.parse( args.message, args.json ) : false);
257-
if ( !parsingSuccessful ){
258-
// report to the user the failure and their locations in the document.
259-
ofLog( OF_LOG_VERBOSE, "[ofxLibwebsockets] Failed to parse JSON\n"+ reader.getFormatedErrorMessages() );
260-
args.json = Json::Value( Json::nullValue );
255+
if ( bParseJSON ){
256+
try {
257+
args.json = ofJson::parse( args.message );
258+
}
259+
catch( std::exception& e ){
260+
// report to the user the failure
261+
args.json.clear();
262+
ofLogVerbose() << "[ofxLibwebsockets] Failed to parse JSON: " << e.what();
263+
}
261264
}
265+
262266
}
263267
}
264268

0 commit comments

Comments
 (0)