e4d2963e01
Based on an earlier piece of source code of mine that parsed JSON into QObjects, this JSON parser creates a BMessage tree. Will be used by Stephan in HaikuDepot for communication with the web app.
34 lines
739 B
C++
34 lines
739 B
C++
/*
|
|
* Copyright 2014, Augustin Cavalier (waddlesplash)
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef JSON_H
|
|
#define JSON_H
|
|
|
|
#include <Message.h>
|
|
#include <String.h>
|
|
|
|
namespace BPrivate {
|
|
|
|
class BJson {
|
|
public:
|
|
enum JsonObjectType {
|
|
JSON_TYPE_MAP = '_JTM',
|
|
JSON_TYPE_ARRAY = '_JTA'
|
|
};
|
|
|
|
public:
|
|
static status_t Parse(BMessage& message, const char* JSON);
|
|
static status_t Parse(BMessage& message, BString& JSON);
|
|
|
|
private:
|
|
static BString _Parser_ParseString(BString& JSON, int32& pos);
|
|
static double _Parser_ParseNumber(BString& JSON, int32& pos);
|
|
static bool _Parser_ParseConstant(BString& JSON, int32& pos,
|
|
const char* constant);
|
|
};
|
|
|
|
} // namespace BPrivate
|
|
|
|
#endif // JSON_H
|