/* static */ void VJSONGraph::Connect( VJSONGraph** inRetainerGraph, const VJSONValue& inRetainedValue) { if (inRetainedValue.IsObject()) Connect( inRetainerGraph, inRetainedValue.GetObject()->GetGraph()); else if (inRetainedValue.IsArray()) Connect( inRetainerGraph, inRetainedValue.GetArray()->GetGraph()); }
VError VJSONBinaryWriter::StreamValue(const VJSONValue& inValue, VMemoryBuffer<>& outBuff) { VError err = VE_OK; sBYTE btype = (sBYTE)inValue.GetType(); outBuff.AddData(&btype, 1); switch( inValue.GetType()) { case JSON_null: case JSON_undefined: case JSON_true: case JSON_false: { break; } case JSON_string: { const VInlineString* s = &(inValue.fString); sLONG len = (sLONG)s->GetLength(); outBuff.AddData(&len, 4); if (len > 0) outBuff.AddData(s->GetCPointer(), len * 2); break; } case JSON_date: { outBuff.AddData(&inValue.fTimeStamp, sizeof(sLONG8)); break; } case JSON_number: { outBuff.AddData(&inValue.fNumber, sizeof(Real)); break; } case JSON_array: { err = StreamArray( inValue.GetArray(), outBuff); break; } case JSON_object: { err = StreamObject( inValue.GetObject(), outBuff); break; } default: xbox_assert( false); } return err; }
VJSONObject* VValueBag::BuildJSONObject(VError& outError) const { // will use stringify until redone in a more elegant way VJSONObject* result = nil; VString jsonstr; outError = GetJSONString(jsonstr); if (outError == VE_OK) { VJSONValue val; outError = val.ParseFromString(jsonstr); if (val.IsObject() && outError == VE_OK) result = RetainRefCountable(val.GetObject()); } return result; }
VError VJSONWriter::StringifyValue( const VJSONValue& inValue, VString& outString) { VError err = VE_OK; switch( inValue.GetType()) { case JSON_undefined: { outString = VJSONValue::sUndefinedString; break; } case JSON_null: { outString = VJSONValue::sNullString; break; } case JSON_true: { outString = VJSONValue::sTrueString; break; } case JSON_false: { outString = VJSONValue::sFalseString; break; } case JSON_string: { VString s; err = inValue.GetString( s); s.GetJSONString( outString, GetOptions()); break; } case JSON_number: { VReal r( inValue.GetNumber()); err = r.GetJSONString( outString, GetOptions()); break; } case JSON_array: { err = StringifyArray( inValue.GetArray(), outString); break; } case JSON_object: { err = StringifyObject( inValue.GetObject(), outString); break; } default: xbox_assert( false); } return err; }
VError VJSONWriter::StringifyValue( const VJSONValue& inValue, VString& outString) { VError err = VE_OK; switch( inValue.GetType()) { case JSON_undefined: { outString = VJSONValue::sUndefinedString; break; } case JSON_null: { outString = VJSONValue::sNullString; break; } case JSON_true: { outString = VJSONValue::sTrueString; break; } case JSON_false: { outString = VJSONValue::sFalseString; break; } case JSON_string: { VString s; err = inValue.GetString( s); s.GetJSONString( outString, GetOptions()); break; } case JSON_date: { VTime dd; VString s; inValue.GetTime(dd); dd.GetJSONString(s); if ((GetOptions() & JSON_AllowDates) != 0) { outString = "\"!!" + s + "!!\""; } else outString = "\"" + s + "\""; break; } case JSON_number: { VReal r( inValue.GetNumber()); err = r.GetJSONString( outString, GetOptions()); break; } case JSON_array: { err = StringifyArray( inValue.GetArray(), outString); break; } case JSON_object: { err = StringifyObject( inValue.GetObject(), outString); break; } default: xbox_assert( false); } return err; }