void VJSGlobalClass::do_dateToIso(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*) { VString s; VJSValue jsval(ioParms.GetContextRef()); if (ioParms.CountParams() > 0) { VTime dd; jsval = ioParms.GetParamValue(1); jsval.GetTime(dd); dd.GetJSONString(s); } ioParms.ReturnString(s); }
VError VJSONValue::GetString( VString& outString) const { VError err = VE_OK; switch( fType) { case JSON_undefined: { outString.Clear(); // not 'undefined'. toString() returns an empty string on an undefined value in a javascript array break; } case JSON_null: { outString.Clear(); // not 'null'. toString() returns an empty string on a null value in a javascript array break; } case JSON_true: { outString = sTrueString; break; } case JSON_false: { outString = sFalseString; break; } case JSON_string: { outString.FromString( fString); break; } case JSON_number: { VReal r( fNumber); err = r.GetJSONString( outString, JSON_Default); break; } case JSON_date: { VTime dd; dd.FromMilliseconds(fTimeStamp); dd.GetJSONString(outString, JSON_Default); break; } case JSON_array: { err = fArray->GetString( outString); break; } case JSON_object: { err = fObject->GetString( 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; }