From 889cf794108dc1a8c4d2c50fc864846799f512e1 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 12 Jun 2019 17:12:15 -0700 Subject: Json objects can be formatted directly. --- src/tests/json.cpp | 6 ++++++ src/unstable/json.cpp | 6 ++++++ src/unstable/json.h | 5 ++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/tests/json.cpp b/src/tests/json.cpp index 6490d8d..6ec92f0 100644 --- a/src/tests/json.cpp +++ b/src/tests/json.cpp @@ -7,6 +7,12 @@ int main( int argc, char *argv[] ) { Bu::Json j( "\x01" "ACTION" "\x01" ); Bu::println( j.toString() ); + + Bu::Json ob( Bu::Json::Object ); + ob.insert("hello", 47.0 ); + const Bu::Json &obRef = ob; + Bu::println("%1").arg( obRef["hello"] ); + return 0; } diff --git a/src/unstable/json.cpp b/src/unstable/json.cpp index 8c766dd..7e6387b 100644 --- a/src/unstable/json.cpp +++ b/src/unstable/json.cpp @@ -832,3 +832,9 @@ void Bu::Json::writeStr( const Bu::UtfString &sStr, Bu::Stream &sOutput ) const sOutput.write("\"", 1 ); } +Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Json &j ) +{ + f.write( j.toString() ); + return f; +} + diff --git a/src/unstable/json.h b/src/unstable/json.h index 2ea62a2..100a3d1 100644 --- a/src/unstable/json.h +++ b/src/unstable/json.h @@ -10,6 +10,7 @@ namespace Bu { class Stream; + class Formatter; typedef Bu::List UtfStringList; class Json @@ -123,6 +124,8 @@ namespace Bu bool bBoolean; } uDat; }; -}; + + Bu::Formatter &operator<<( Bu::Formatter &f, const Bu::Json &j ); +} #endif -- cgit v1.2.3