Exemplo n.º 1
0
        public void mapJsonStringTest()
        {
            Dictionary <object, object> m = new Dictionary <object, object>();

            m.Add("testString", "didididi");
            m.Add("testInt", 100);
            m.Add("testInt2", "100");
            m.Add("testBoolean", "true");
            ParamTestModel model = new ParamTestModel();

            model.setAction("testAction");
            ParamTypeModel typeModel = new ParamTypeModel();

            typeModel.setAlarmStatus("status");
            typeModel.setInstanceClass(10);
            m.Add("testObject", typeModel);

            String d = QSStringUtil.getDictionaryToJson(m);

            Console.WriteLine(d);
            Object o = QSJSONUtil.convertJSONObject(d);

            Assert.IsNotNull(o);
            Dictionary <String, Object> dic = QSJSONUtil.JsonToDictionary(d);

            Assert.AreEqual(dic["testString"], "didididi");
            Assert.AreEqual(Convert.ToInt32(dic["testInt2"]), 100);
        }
Exemplo n.º 2
0
        public void put_bucket_external_mirror(String arg1)
        {
            // Write code here that turns the phrase above into concrete actions
            EvnContext evnContext = TestUtil.getEvnContext();

            Bucket = new Bucket(evnContext, bucketName);
            Bucket.PutBucketExternalMirrorInput input = new Bucket.PutBucketExternalMirrorInput();
            string obj = QSJSONUtil.convertJSONObject(arg1);

            input.setSourceSite(QSJSONUtil.toString(obj, "source_site"));
            putBucketExternalMirrorOutput = Bucket.putExternalMirror(input);
        }
Exemplo n.º 3
0
        public void testJson()
        {
            Dictionary <String, object> obj = new Dictionary <string, object>();

            obj.Add("testString", "test");
            obj.Add("testInt", 123);
            obj.Add("testList", "[{'test':'test'}]");
            String convertObj =
                QSJSONUtil.convertJSONObject(obj);
            Dictionary <String, Object> dic = QSJSONUtil.JsonToDictionary(convertObj);

            Assert.AreEqual(dic["testString"], "test");
            Assert.AreEqual(dic["testInt"], 123);
        }
        private void fillResponseValue2Object(HttpWebResponse response, OutputModel target)
        {
            int          code           = Convert.ToInt32(response.StatusCode);
            Stream       receviceStream = response.GetResponseStream();
            StreamReader readerOfStream = new StreamReader(receviceStream);
            string       strHTML        = readerOfStream.ReadToEnd();
            string       body           = strHTML;//.Replace("\"","");//System.Text.RegularExpressions.Regex.Replace(strHTML,"(?is)(?<=<body>).*(?=</body>)","");
            String       st             = QSJSONUtil.toJSONObject("");

            st = QSJSONUtil.putJsonData(st, QSConstant.PARAM_TYPE_BODYINPUTSTREAM, body);
            if (target != null)
            {
                if (!QSJSONUtil.jsonObjFillValue2Object(st, target))
                {
                    try
                    {
                        string responseInfo = body;
                        // Deserialize HTTP response to concrete type.
                        if (!QSStringUtil.isEmpty(responseInfo))
                        {
                            QSJSONUtil.jsonFillValue2Object(responseInfo, target);
                        }
                    }
                    catch (Exception e)
                    {
                        throw new Exception(e.Message);
                    }
                }
                WebHeaderCollection responseHeaders = response.Headers;
                int    iHeads   = responseHeaders.Count;
                string headJson = QSJSONUtil.toJSONObject("");
                headJson = QSJSONUtil.putJsonData(headJson, QSConstant.QC_CODE_FIELD_NAME, code);
                for (int i = 0; i < iHeads; i++)
                {
                    QSJSONUtil.putJsonData(headJson, responseHeaders.GetKey(i), responseHeaders.GetValues(i));
                }
                QSJSONUtil.jsonObjFillValue2Object(headJson, target);
            }
        }
        public static void fillResponseCallbackModel(int code, Object content, OutputModel model)
        {
            string errorJson = "{'" + QSConstant.QC_CODE_FIELD_NAME + "':" + code + ",'" + QSConstant.QC_MESSAGE_FIELD_NAME + "':'" + content + "'}";

            QSJSONUtil.jsonFillValue2Object(errorJson, model);
        }