Beispiel #1
0
VError VJSONArray::Clone( VJSONValue& outValue, VJSONCloner& inCloner) const
{
    VError err = VE_OK;

    VJSONArray *clone = new VJSONArray;
    if (clone != NULL)
    {
        VectorType clonedVector = fVector;

        for( VectorType::iterator i = clonedVector.begin() ; (i != clonedVector.end()) && (err == VE_OK) ; ++i)
        {
            if (i->IsObject())
            {
                VJSONObject *theOriginalObject = RetainRefCountable( i->GetObject());
                err = inCloner.CloneObject( theOriginalObject, *i);
                VJSONGraph::Connect( &clone->fGraph, *i);
                ReleaseRefCountable( &theOriginalObject);
            }
            else if (i->IsArray())
            {
                VJSONArray *theOriginalArray = RetainRefCountable( i->GetArray());
                err = theOriginalArray->Clone( *i, inCloner);
                VJSONGraph::Connect( &clone->fGraph, *i);
                ReleaseRefCountable( &theOriginalArray);
            }
        }

        if (err == VE_OK)
            clone->fVector.swap( clonedVector);
    }
    else
    {
        err = VE_MEMORY_FULL;
    }
    outValue.SetArray( clone);
    ReleaseRefCountable( &clone);

    return err;
}
Beispiel #2
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;
}