Пример #1
0
void VJSONValue::GetTime(VTime& outTime) const
{
	VError err = VE_OK;
	switch (fType)
	{

		case JSON_string:
		{
			VString s;
			s.FromString(fString);
			outTime.FromString(s);
			break;
		}

		case JSON_date:
		{
			outTime.FromMilliseconds(fTimeStamp);
			break;
		}

		case JSON_number:
		{
			outTime.FromMilliseconds(fNumber);
			break;
		}

		default:
		{
			outTime.Clear();
			outTime.SetNull(true);
			break;
		}
	}
}
Пример #2
0
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;
}
Пример #3
0
VError VJSONBinaryImporter::GetValue(VJSONValue& outVal)
{
	VError err = VE_OK;
	sBYTE btype = *((uBYTE*)fCurPtr);
	++fCurPtr;
	switch (btype)
	{
		case JSON_null:
			outVal.SetNull();
			break;

		case JSON_undefined:
			outVal.SetUndefined();
			break;

		case JSON_true:
			outVal.SetBool(true);
			break;

		case JSON_false:
			outVal.SetBool(false);
			break;

		case JSON_string:
			{
				VString s;
				sLONG len = *((sLONG*)fCurPtr);
				fCurPtr += 4;
				s.FromBlock(fCurPtr, len * 2, VTC_UTF_16);
				fCurPtr += (len * 2);
				outVal.SetString(s);
			}
			break;

		case JSON_date:
			{
				VTime dd;
				sLONG8 ll = *((sLONG8*)fCurPtr);
				fCurPtr += 8;
				dd.FromMilliseconds(ll);
				outVal.SetTime(dd);
			}
			break;

		case JSON_number:
			{
				Real rr = *((Real*)fCurPtr);
				fCurPtr += sizeof(Real);
				outVal.SetNumber(rr);
			}
			break;

		case JSON_object:
			{
				if (*((sWORD*)fCurPtr) == -2)
				{
					outVal.SetUndefined();
				}
				else
				{
					VJSONObject* obj = new VJSONObject();
					sWORD len;
					do
					{
						len = *((sWORD*)fCurPtr);
						fCurPtr += 2;
						if (len >= 0)
						{
							VString name;
							name.FromBlock(fCurPtr, (sLONG)len * 2, VTC_UTF_16);
							fCurPtr += ((sLONG)len * 2);
							VJSONValue val;
							err = GetValue(val);
							obj->SetProperty(name, val);
						}
					} while (err == VE_OK && len != -1);
					outVal.SetObject(obj);
					QuickReleaseRefCountable(obj);
				}
			}
			break;

		case JSON_array:
			{
				sLONG count = *((sLONG*)fCurPtr);
				fCurPtr += 4;
				if (count == -2)
				{
					outVal.SetUndefined();
				}
				else
				{
					VJSONArray* arr = new VJSONArray();
					for (sLONG i = 0; i < count && err == VE_OK; ++i)
					{
						VJSONValue val;
						err = GetValue(val);
						arr->Push(val);
					}
					outVal.SetArray(arr);
					QuickReleaseRefCountable(arr);
				}
			}
			break;

		default:
			xbox_assert(false);
			break;
	}
	return err;
}