示例#1
0
        public static KnetikJSONNode Deserialize(System.IO.BinaryReader aReader)
        {
            KnetikJSONBinaryTag type = (KnetikJSONBinaryTag)aReader.ReadByte();
            switch(type)
            {
                case KnetikJSONBinaryTag.Array:
                {
                    int count = aReader.ReadInt32();
                    KnetikJSONArray tmp = new KnetikJSONArray();
                    for(int i = 0; i < count; i++)
                        tmp.Add(Deserialize(aReader));
                    return tmp;
                }
                case KnetikJSONBinaryTag.Class:
                {
                    int count = aReader.ReadInt32();
                    KnetikJSONClass tmp = new KnetikJSONClass();
                    for(int i = 0; i < count; i++)
                    {
                        string key = aReader.ReadString();
                        var val = Deserialize(aReader);
                        tmp.Add(key, val);
                    }
                    return tmp;
                }
                case KnetikJSONBinaryTag.Value:
                {
                    return new KnetikJSONData(aReader.ReadString());
                }
                case KnetikJSONBinaryTag.IntValue:
                {
                    return new KnetikJSONData(aReader.ReadInt32());
                }
                case KnetikJSONBinaryTag.DoubleValue:
                {
                    return new KnetikJSONData(aReader.ReadDouble());
                }
                case KnetikJSONBinaryTag.BoolValue:
                {
                    return new KnetikJSONData(aReader.ReadBoolean());
                }
                case KnetikJSONBinaryTag.FloatValue:
                {
                    return new KnetikJSONData(aReader.ReadSingle());
                }

                default:
                {
                    throw new Exception("Error deserializing JSON. Unknown tag: " + type);
                }
            }
        }
示例#2
0
 public override KnetikJSONNode this[int aIndex]
 {
     get
     {
         return new KnetikJSONLazyCreator(this);
     }
     set
     {
         var tmp = new KnetikJSONArray();
         tmp.Add(value);
         Set(tmp);
     }
 }
示例#3
0
 public override void Add(KnetikJSONNode aItem)
 {
     var tmp = new KnetikJSONArray();
     tmp.Add(aItem);
     Set(tmp);
 }
示例#4
0
        public KnetikApiResponse CartCreateWithVirtualCurrency(KnetikJSONArray currencies,CatalogSku catlog,Action<KnetikApiResponse> cb = null)
        {
            StringBuilder createCartBuilder = new StringBuilder();
            createCartBuilder.Append(CartCreateEndpoint);

            JSONObject j = new JSONObject (JSONObject.Type.OBJECT);
            if (catlog.Item != null) {
                if(catlog.Item.TypeHint == "virtual_item" || catlog.CurrencyId != 0)
                {
                    foreach(KnetikJSONNode element in currencies)
                    {
                        if(element["id"].AsInt == catlog.CurrencyId)
                        {
                            createCartBuilder.Append("?currency_code="+element["code"].Value);
                        }
                    }

                }
            }

            String body = j.Print ();

            KnetikRequest req = CreateRequest(createCartBuilder.ToString(), body);

            KnetikApiResponse response = new KnetikApiResponse(this, req, cb);
            return  response;
        }