ToString() public method

public ToString ( ) : string
return string
        public void StringsTest()
        {
            JsonWriter writer = new JsonWriter();

            writer.WriteArrayStart();
            writer.Write("Hello World!");
            writer.Write("\n\r\b\f\t");
            writer.Write("I \u2665 you");
            writer.Write("She said, \"I know what it's like to be dead\"");
            writer.WriteArrayEnd();

            string json =
                "[\"Hello World!\",\"\\n\\r\\b\\f\\t\",\"I \\u2665 you\"" +
                ",\"She said, \\\"I know what it's like to be dead\\\"\"]";

            Assert.AreEqual(json, writer.ToString(), "A1");
        }
Example #2
0
        public void TestZero()
        {
            var t1 = new Values();

            var wr = new JsonWriter(indented: false);

            new JsonSerializer().Serialize(t1, wr);
            string json = wr.ToString();

            Assert.AreEqual(@"{""b"":false,""s8"":0,""u8"":0,""s16"":0,""u16"":0,""s32"":0,""u32"":0,""s64"":0,""u64"":0,""f32"":0,""f64"":0}", json);

            var t2 = new JsonDeserializer().Deserialize <Values>(json);

            Assert.AreEqual(false, t2.B);
            Assert.AreEqual(0, t2.S32);
            Assert.AreEqual(0U, t2.U32);
        }
Example #3
0
    /// <summary>
    /// 写入新的数据
    /// </summary>
    /// <param name="id"></param>
    static JsonData WriterTileJson(int id)
    {
        JsonWriter writer = new JsonWriter();

        writer.WriteObjectStart();

        writer.WritePropertyName("id");
        writer.Write(id);

        writer.WriteObjectEnd();

        string data = writer.ToString();

        SaveData(data, id, DataType.TileList);

        return(JsonMapper.ToObject(data));
    }
Example #4
0
        /// <summary>
        /// 获取数据的总记录数
        /// </summary>
        private void GetDataTotal()
        {
            string condition  = MakeConditionString <DBControl.DBInfo.Tables.Attachment>(HttpContext.Current, "s_");
            bool   IsGetTotal = UrlHelper.ReqBoolByGetOrPost("isgettotal", true);

            if (IsGetTotal)
            {
                _total = DBControl.Base.DBAccess.Count <DBControl.DBInfo.Tables.Attachment>(condition);
            }
            JsonObject jsonData = JsonResult(true, enumReturnTitle.GetData, "数据获取成功。");

            jsonData.Add("total", _total);
            JsonWriter jWriter = new JsonWriter();

            jsonData.Write(jWriter);
            CurrentContext.Response.Write(jWriter.ToString());
        }
Example #5
0
        private void GetCourseWareFilesByBatchGUID()
        {
            string BatchGUID = UrlHelper.ReqStrByGetOrPost("batchguid");

            IDataReader idr = attaBllExt.GetDataByBatchGUID(BatchGUID);

            string[] fieldArr = new string[] {
                "[AttachID]"

                , "[AttachGUID]"

                , "[FileName]"

                , "[Fix]"

                , "[FileType]"

                , "[RelativeURL]"

                , "[FileSize]"

                , "[Description]"

                , "[OrderNum]"
            };
            JsonObject jsonData = JsonResult(false, enumReturnTitle.GetData, "数据获取失败。");
            JsonArray  jArray   = DataListToJson(idr, "OrderNum", _descOrder, ref _minid, ref _maxid, fieldArr);

            if (jArray.Count > 0)
            {
                jsonData = JsonResult(true, enumReturnTitle.GetData, "数据获取成功。");

                jsonData.Add("rowsccount", jArray.Count);

                jsonData.Add("rows", jArray);
            }
            else
            {
                jsonData = JsonResult(false, enumReturnTitle.GetData, "没数据。");
            }
            JsonWriter jWriter = new JsonWriter();

            jsonData.Write(jWriter);
            CurrentContext.Response.Write(jWriter.ToString());
        }
Example #6
0
        public void GetJsonDataByID()
        {
            string id = UrlHelper.ReqStr("id");

            if (!string.IsNullOrWhiteSpace(id))
            {
                /*******************  字段 可修改区域 Start  **********************/
                string[] fieldArr = new string[] {
                    "[ID]"

                    , "[CategoryCode]"

                    , "[DataKey]"

                    , "[DataValue]"

                    , "[OrderNumber]"
                };
                /*******************  字段 可修改区域 End  **********************/
                try
                {
                    IDataReader idr = DBControl.Base.DBAccess.GetDataIDR(fieldArr, _tableName, string.Format(" {0}={1}", _idField, id), string.Empty);

                    JsonObject jsonData = JsonResult(false, enumReturnTitle.GetData, "数据获取失败。");
                    JsonObject tempdata = OneDataRecordToJson(idr);
                    if (tempdata.Keys.Count > 0)
                    {
                        jsonData = JsonResult(true, enumReturnTitle.GetData, "数据获取成功。");
                        jsonData.Add("Data", tempdata);
                    }

                    JsonWriter jWriter = new JsonWriter();
                    jsonData.Write(jWriter);
                    CurrentContext.Response.Write(jWriter.ToString());
                }
                catch (Exception ex)
                {
                    ReturnMsg(false, enumReturnTitle.GetData, ex.Message);
                }
            }
            else
            {
                ReturnMsg(false, enumReturnTitle.GetData, "获取数据失败,请传递一个有效的ID值。");
            }
        }
Example #7
0
        public void ObjectTest()
        {
            JsonWriter writer = new JsonWriter();

            string json = "{\"flavour\":\"strawberry\",\"color\":\"red\"," +
                          "\"amount\":3}";

            writer.WriteObjectStart();
            writer.WritePropertyName("flavour");
            writer.Write("strawberry");
            writer.WritePropertyName("color");
            writer.Write("red");
            writer.WritePropertyName("amount");
            writer.Write(3);
            writer.WriteObjectEnd();

            Assert.AreEqual(writer.ToString(), json);
        }
Example #8
0
    public void CreateJson()
    {
        //申明json写入对象,花括号
        JsonWriter writer = new JsonWriter();

        //第一种{对象写入}
        writer.WriteObjectStart();
        writer.WritePropertyName("Attack");
        writer.Write("10");
        writer.WritePropertyName("AttackRange");
        writer.Write("100");
        writer.WritePropertyName("BulletName");
        writer.Write("CubeBullet");
        //结束json对象写入
        writer.WriteObjectEnd();
        print(writer.ToString());
        //
    }
Example #9
0
    static public void SaveStageInfo(BattleGroup battleGroup)
    {
        BattleSaveDataStage data = new BattleSaveDataStage(battleGroup);

        //stageData.id = "Battle_2";
        //Debug.Log("스테이지 저장");
        JsonWriter jsonWriter = new JsonWriter();

        jsonWriter.PrettyPrint = true;
        JsonMapper.ToJson(data, jsonWriter);
        string json = jsonWriter.ToString();
        //string json2 = JsonUtility.ToJson(data);  //이걸로 하면 몇몇 타입의 필드가 json에서 누락됨

        string fileName = Application.persistentDataPath + "/" + battleGroup.battleType + "_" + User.Instance.userID + "_Stage.dat";

        File.WriteAllText(fileName, json);
        SaveHeroProficiency(battleGroup);
    }
Example #10
0
        public static string serializeToJson(object data, bool usePrintableFormatting)
        {
            string     result     = "";
            JsonWriter jsonWriter = new JsonWriter();

            jsonWriter.PrettyPrint = usePrintableFormatting;
            try
            {
                JsonMapper.ToJson(data, jsonWriter);
                result = jsonWriter.ToString();
            }
            catch (JsonException ex)
            {
                Logger.LogFatal(typeof(JSONManager), "Error serializing data to JSON. " + ex.ToString(), Logger.TagFlags.ASSET);
                OnErrorEvent(EventArgs.Empty);
            }
            return(result);
        }
Example #11
0
        private void button2_Click(object sender, EventArgs e)
        {
            var dt = GetSql("SELECT * FROM rec");
            var jw = new JsonWriter();

            jw.WriteArrayStart();

            var lasttime = "";

            foreach (DataRow r in dt.Rows)
            {
                if (r["timesamp"].ToString() == lasttime)
                {
                    continue;
                }


                if (r["totalcount"].ToString() == "")
                {
                    continue;
                }

                jw.WriteObjectStart();

                jw.WritePropertyName("timesamp");
                jw.Write(r["timesamp"].ToString());



                jw.WritePropertyName("totalcount");
                jw.Write(r["totalcount"].ToString());


                jw.WriteObjectEnd();
                lasttime = r["timesamp"].ToString();
            }
            jw.WriteArrayEnd();

            var fs = File.Create("data2.json");
            var bs = Encoding.UTF8.GetBytes(jw.ToString());

            fs.Write(bs, 0, bs.Length);
            fs.Close();
        }
Example #12
0
        void FilterList(WebData webData, ITable table, string nameField, string guidField, string text)
        {
            var ids = new Set <long>();

            if (text == null)
            {
                ids.IncludeRange(table.FindRows(Search.None, ResultOption.Limit(20)));
            }
            else
            {
                ids.AddRange(table.FindRows(Search.FieldLike(nameField, MDBSearch.Text(text + "%")) & Search.FieldNotEquals(guidField, null), ResultOption.SortAscending(nameField) + ResultOption.Group(nameField) + ResultOption.Group(guidField) + ResultOption.Limit(20)));
                if (ids.Count < 20)
                {
                    ids.IncludeRange(table.FindRows(Search.FieldLike(nameField, MDBSearch.Text("% " + text + "%")) & Search.FieldNotEquals(guidField, null), ResultOption.SortAscending(nameField) + ResultOption.Group(nameField) + ResultOption.Group(guidField) + ResultOption.Limit(20)));
                }
                if (ids.Count < 20)
                {
                    ids.IncludeRange(table.FindRows(Search.FieldLike(nameField, MDBSearch.Text(text + "%")) & Search.FieldEquals(guidField, null), ResultOption.SortAscending(nameField) + ResultOption.Group(nameField) + ResultOption.Limit(20 - ids.Count)));
                }
                if (ids.Count < 20)
                {
                    ids.IncludeRange(table.FindRows(Search.FieldLike(nameField, MDBSearch.Text("% " + text + "%")) & Search.FieldEquals(guidField, null), ResultOption.SortAscending(nameField) + ResultOption.Group(nameField) + ResultOption.Limit(20 - ids.Count)));
                }
            }
            var json = new JsonWriter();

            json.BeginArray("results");
            if (ids.Count > 0)
            {
                //get items
                var values = table.GetValues <string>(nameField, false, ids.SubRange(0, Math.Min(20, ids.Count)));
                foreach (var value in values)
                {
                    json.BeginObject();
                    json.String("id", value);
                    json.String("text", value);
                    json.EndObject();
                }
            }
            json.EndArray();
            var message = WebMessage.Create(webData.Method, $"Filter {nameField} {text}");

            webData.Answer = WebAnswer.Json(webData.Request, message, json.ToString());
        }
Example #13
0
        public static string Serialize()
        {
            var dto = new MusicDTO.EditData();

            dto.BPM      = EditData.BPM.Value;
            dto.maxBlock = EditData.MaxBlock.Value;
            dto.offset   = EditData.OffsetSamples.Value;
            dto.name     = Path.GetFileNameWithoutExtension(EditData.Name.Value);

            var sortedNoteObjects = EditData.Notes.Values
                                    .Where(note => !(note.note.type == NoteTypes.Long && EditData.Notes.ContainsKey(note.note.prev)))
                                    .OrderBy(note => note.note.position.ToSamples(Audio.Source.clip.frequency, EditData.BPM.Value));

            dto.notes = new List <MusicDTO.Note>();

            foreach (var noteObject in sortedNoteObjects)
            {
                if (noteObject.note.type == NoteTypes.Single)
                {
                    dto.notes.Add(ToDTO(noteObject));
                }
                else if (noteObject.note.type == NoteTypes.Long)
                {
                    var current = noteObject;
                    var note    = ToDTO(noteObject);

                    while (EditData.Notes.ContainsKey(current.note.next))
                    {
                        var nextObj = EditData.Notes[current.note.next];
                        note.notes.Add(ToDTO(nextObj));
                        current = nextObj;
                    }

                    dto.notes.Add(note);
                }
            }

            var jsonWriter = new JsonWriter();

            jsonWriter.PrettyPrint = true;
            jsonWriter.IndentValue = 4;
            JsonMapper.ToJson(dto, jsonWriter);
            return(jsonWriter.ToString());
        }
Example #14
0
        /// <summary>
        /// Method to serialize MonitoringAPICallEvent CSM event to json.
        /// </summary>
        private static bool CreateUDPMessage(MonitoringAPICallEvent monitoringAPICallEvent, out string response)
        {
            JsonWriter jw = new JsonWriter();

            jw.WriteObjectStart();

            jw = CreateUDPMessage(monitoringAPICallEvent, jw);

            jw.WritePropertyName("Latency");
            jw.Write(monitoringAPICallEvent.Latency);

            jw.WritePropertyName("AttemptCount");
            jw.Write(monitoringAPICallEvent.AttemptCount);

            jw.WriteObjectEnd();
            response = jw.ToString();

            return(ASCIIEncoding.Unicode.GetByteCount(response) <= (8 * 1024));
        }
Example #15
0
        /// <summary>
        /// 根据表名称或表名与值获取键值对json数据
        /// </summary>
        private void GetKeyValueJsonDataByDataTable()
        {
            JsonObject jsonData   = JsonResult(false, enumReturnTitle.GetData, "数据获取失败。");
            string     DataTable  = UrlHelper.ReqStr("DataTable");
            string     KeyField   = UrlHelper.ReqStr("KeyField");
            string     ValueField = UrlHelper.ReqStr("ValueField");
            bool       IsSingle   = UrlHelper.ReqBoolByGetOrPost("IsSingle");
            string     Val        = UrlHelper.ReqStr("Val");
            string     condition  = "";

            if (IsSingle)
            {
                condition = string.Format(" {0}='{1}' ", ValueField, Val);
            }
            try
            {
                IDataReader idr    = DBControl.Base.DBAccess.GetDataIDR(string.Format("{0},{1}", KeyField, ValueField), DataTable, condition, "");
                JsonArray   jArray = new JsonArray();
                if (null != idr)
                {
                    jsonData = JsonResult(true, enumReturnTitle.GetData, "数据获取成功。");
                    int index = 0;
                    while (idr.Read())
                    {
                        JsonObject tempObj = new JsonObject();
                        tempObj.Add("DataValue", idr[ValueField].ToString());
                        tempObj.Add("DataKey", idr[KeyField].ToString());
                        jArray.Add(tempObj);
                        index++;
                    }
                    idr.Close();
                    idr.Dispose();
                }
                jsonData.Add("rows", jArray);
                JsonWriter jWriter = new JsonWriter();
                jsonData.Write(jWriter);
                CurrentContext.Response.Write(jWriter.ToString());
            }
            catch (Exception ex)
            {
                ReturnMsg(false, enumReturnTitle.GetData, string.Format("获取数据失败:{0}", ex.Message));
            }
        }
Example #16
0
        public void PrimitiveWrapperUtf16()
        {
            var jsonWriter = new JsonWriter <char>();

            jsonWriter.WriteBeginArray();
            jsonWriter.WriteInt32(1);
            jsonWriter.WriteEndArray();

            var output = jsonWriter.ToString();

            var jsonReader = new JsonReader <char>(output);

            jsonReader.ReadBeginArrayOrThrow();
            var value = jsonReader.ReadInt32();

            jsonReader.ReadEndArrayOrThrow();

            Assert.Equal(1, value);
        }
Example #17
0
        internal void Persist(StreamWriter writer)
        {
            JsonWriter jsonWriter = new JsonWriter();

            jsonWriter.PrettyPrint = true;

            jsonWriter.WriteObjectStart();
            foreach (var key in this._values.Keys)
            {
                ObjectSettings os = this[key];
                jsonWriter.WritePropertyName(key);
                os.WriteToJson(jsonWriter);
            }
            jsonWriter.WriteObjectEnd();

            string content = jsonWriter.ToString();

            writer.Write(content);
        }
Example #18
0
        public override string Serialize(object target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            Type targetType = target.GetType();
            var  writer     = new JsonWriter();
            var  formatter  = (IJsonFormatter <object>)Resolver.GetFormatter(targetType);

            formatter.Serialize(ref writer, target, Resolver);

            string text = Readable
                ? JsonSerializer.PrettyPrint(writer.ToUtf8ByteArray())
                : writer.ToString();

            return(text);
        }
Example #19
0
    public string SerializeNotesData()
    {
        var data = new MusicModel.NotesData();

        data.BPM    = BPM.Value;
        data.offset = BeatOffsetSamples.Value;
        data.name   = Path.GetFileNameWithoutExtension(MusicName.Value);

        var sortedNoteObjects = NoteObjects.Values
                                .Where(note => !(note.noteType.Value == NoteTypes.Long && note.prev != null))
                                .OrderBy(note => note.notePosition.ToSamples(Audio.clip.frequency));

        data.notes = new List <MusicModel.Note>();

        foreach (var noteObject in sortedNoteObjects)
        {
            if (noteObject.noteType.Value == NoteTypes.Normal)
            {
                data.notes.Add(ConvertToNote(noteObject));
            }
            else if (noteObject.noteType.Value == NoteTypes.Long)
            {
                var current = noteObject;
                var note    = ConvertToNote(noteObject);

                while (current.next != null)
                {
                    note.notes.Add(ConvertToNote(current.next));
                    current = current.next;
                }

                data.notes.Add(note);
            }
        }

        var jsonWriter = new JsonWriter();

        jsonWriter.PrettyPrint = true;
        jsonWriter.IndentValue = 4;
        JsonMapper.ToJson(data, jsonWriter);
        return(jsonWriter.ToString());
    }
Example #20
0
        public void TestString()
        {
            var t1 = new TypedValues <string>()
            {
                IgnoredValue = "100", DirectValue = "200", PropertyValue = "300"
            };

            var wr = new JsonWriter(indented: false);

            new JsonSerializer().Serialize(t1, wr);
            string json = wr.ToString();

            Assert.AreEqual(@"{""a"":""200"",""b"":""300""}", json);

            var t2 = new JsonDeserializer().Deserialize <TypedValues <string> >(json);

            Assert.AreEqual(null, t2.IgnoredValue);
            Assert.AreEqual("200", t2.DirectValue);
            Assert.AreEqual("300", t2.PropertyValue);
        }
Example #21
0
        public void GetAllJsonTreeData(HttpContext context, string idField, string pidField, params string[] fieldArr)
        {
            IDataReader idr0 = DBControl.Base.DBAccess.GetDataIDR(fieldArr, _tableName, string.Format(" {0}=0", pidField), _orderBy);

            if (null != idr0)
            {
                JsonArray  JsonData       = GetJsonArrayForTreeData(idr0, idField, pidField, fieldArr);
                JsonObject jsonObjDefault = new JsonObject();
                jsonObjDefault.Add("id", "");
                jsonObjDefault.Add("text", "---请选择---");
                JsonData.Insert(0, jsonObjDefault);
                JsonWriter jwriter = new JsonWriter();
                JsonData.Write(jwriter);
                context.Response.Write(jwriter.ToString());
            }
            else
            {
                context.Response.Write(string.Empty);
            }
        }
Example #22
0
        public void TestInteger()
        {
            var t1 = new TypedValues <int>()
            {
                IgnoredValue = 100, DirectValue = 200, PropertyValue = 300
            };

            var wr = new JsonWriter(indented: false);

            new JsonSerializer().Serialize(t1, wr);
            string json = wr.ToString();

            Assert.AreEqual(@"{""a"":200,""b"":300}", json);

            var t2 = new JsonDeserializer().Deserialize <TypedValues <int> >(json);

            Assert.AreEqual(0, t2.IgnoredValue);
            Assert.AreEqual(200, t2.DirectValue);
            Assert.AreEqual(300, t2.PropertyValue);
        }
Example #23
0
        public void test_primitive_property_polymorphism()
        {
            var input = new TestTypedPrimitivePropPoly();

            input.prop = "string";
            JsonWriter writer = new JsonWriter();

            writer.TypeHinting = true;
            JsonMapper.ToJson(input, writer);
            string json = writer.ToString();

            Assert.IsNotNull(json);
            JsonReader reader = new JsonReader(json);

            reader.TypeHinting = true;
            var output = JsonMapper.ToObject <TestTypedPrimitivePropPoly>(reader);

            Assert.IsNotNull(output);
            Assert.AreEqual("string", output.prop);
        }
Example #24
0
    IEnumerator PostTest1()
    {
        string str = @"";
        // string like this
        // str = @"{""Id"":0,""IMEI"":""String"",""Phone"":""String"",""Name"":""String"",""Status"":0,""CreateTime"":""\/Date(-62135596800000+0800)\/"",""UpdateTime"":""\/Date(-62135596800000+0800)\/""}";
        // write Json
        JsonWriter writer = new JsonWriter();
        writer.WriteObjectStart();
        writer.WritePropertyName("Id");
        writer.Write(0);
        writer.WritePropertyName("IMEI");
        writer.Write("7654321");
        writer.WritePropertyName("Phone");
        writer.Write("13802817183");
        writer.WritePropertyName("Name");
        writer.Write("bbzm");
        writer.WritePropertyName("Status");
        writer.Write("1");
        writer.WritePropertyName("CreateTime");
        writer.Write("2013-01-01");
        writer.WritePropertyName("UpdateTime");
        writer.Write("2013-10-10");
        writer.WriteObjectEnd();
        str = writer.ToString();

        Debug.Log(str);
        WWWForm parameter = new WWWForm();
        parameter.AddField("Body", str);

        WWW postRequest = new WWW(@"http://192.168.133.225:82/Client/123456?format=json", parameter);
        yield return postRequest;

        JsonReader read = new JsonReader(postRequest.text);
        Debug.Log(postRequest.text);
        Debug.Log(" ----------------- ");
        while (read.Read())
        {
            Debug.Log(read.Token + " : " + read.Value + " : " + read.GetType().ToString());
        }
        Debug.Log(" ----------------- ");
    }
Example #25
0
    // 인터페이스 : 리소스 리스트를 Json형태로 쓰기
    public static void SaveToResourcesInfo(Dictionary <string, SHResourcesInfo> dicTable, string strSaveFilePath)
    {
        if (0 == dicTable.Count)
        {
            return;
        }

        var pResourcesJsonData = new JsonData();

        foreach (var kvp in dicTable)
        {
            pResourcesJsonData.Add(MakeResourceJsonData(kvp.Value));
        }

        var pJsonWriter = new JsonWriter();

        pJsonWriter.PrettyPrint = true;
        JsonMapper.ToJson(pResourcesJsonData, pJsonWriter);

        SHUtils.SaveFile(pJsonWriter.ToString(), strSaveFilePath);
    }
Example #26
0
        public static HttpResponseMessage JsonResponseJson(this ApiController controller, long code, string description, Dictionary <string, string> extraJsons)
        {
            JsonWriter writer = new JsonWriter(64);

            writer.WriteStartObject();

            writer.Write("Code", code);
            if (!string.IsNullOrEmpty(description))
            {
                writer.Write("Description", description);
            }

            foreach (KeyValuePair <string, string> pair in extraJsons)
            {
                writer.WriteRaw(pair.Key, pair.Value);
            }

            writer.WriteEndObject();

            return(JsonString(controller, writer.ToString()));
        }
Example #27
0
    void Start()
    {
        ExampleSerializedClass serializedClass = new ExampleSerializedClass();

        JsonWriter writer = new JsonWriter();

        writer.PrettyPrint = true;

        JsonMapper.ToJson(serializedClass, writer);

        string json = writer.ToString();

        Debug.Log(json);

        // If you don't need a JsonWriter, use this.
        //string json = JsonMapper.ToJson(exampleClass);

        ExampleSerializedClass deserializedClass = JsonMapper.ToObject <ExampleSerializedClass>(savedJsonString);

        Debug.Log(deserializedClass.myString);
    }
Example #28
0
        public void TestSimple()
        {
            var t1 = new TypedValues()
            {
                IgnoredValue = 100, DirectValue = 200, PropertyValue = 300, TestValue = int.MinValue
            };

            var wr = new JsonWriter(indented: false);

            new JsonSerializer().Serialize(t1, wr);
            string json = wr.ToString();

            Assert.AreEqual(@"{""a"":200,""b"":300,""c"":-2147483648}", json);

            var t2 = new JsonDeserializer().Deserialize <TypedValues>(json);

            Assert.AreEqual(0, t2.IgnoredValue);
            Assert.AreEqual(200, t2.DirectValue);
            Assert.AreEqual(300, t2.PropertyValue);
            Assert.AreEqual(int.MinValue, t2.TestValue);
        }
Example #29
0
        public static ContentResult JsonResult(this Controller controller, long code, string description, Dictionary <string, object> extraValues)
        {
            JsonWriter writer = new JsonWriter(64);

            writer.WriteStartObject();

            writer.Write("Code", code);
            if (!string.IsNullOrEmpty(description))
            {
                writer.Write("Description", description);
            }

            foreach (KeyValuePair <string, object> pair in extraValues)
            {
                writer.Write(pair.Key, pair.Value);
            }

            writer.WriteEndObject();

            return(JsonString(controller, writer.ToString()));
        }
Example #30
0
        public string Sign()
        {
            var w = new JsonWriter {
                PrettyPrint = false, IndentValue = 0
            };

            w.WriteObjectStart();
            foreach (var s in claims.Values)
            {
                s.Serialize(w);
            }
            w.WriteObjectEnd();

            var    key           = _config.Key;
            string headerSegment = GetHeaderSegment(key);
            var    claimSegment  = w.ToString().Base64UrlEncode();

            var signer    = _cryptoProvider.GetSigner();
            var signature = signer.GetSignature(headerSegment + "." + claimSegment);

            return(headerSegment + "." + claimSegment + "." + signature.Base64UrlEncode());
        }
    // Use this for initialization
    void Start()
    {
        CustomData customData = new CustomData();

        customData.Add("customKey1", "customValue1");
        customData.Add("customKey2", "customValue2");

        int[] coordinates = { 1, 2, 3 };

        TrackingEventData data = new TrackingEventDataWithoutIDs(
            TrackingEvent.START,
            customData,
            "map1.level1.section1",
            coordinates
            );

        //*
        JsonWriter writer = new JsonWriter();

        writer.PrettyPrint = true;

        JsonMapper.ToJson(data, writer);

        string json = writer.ToString();

        Debug.Log("obj=" + data);
        Debug.Log("serialized=" + json);

        TrackingEventData deserializedData = JsonMapper.ToObject <TrackingEventData>(json);

        /*/
         *
         * // If you don't need a JsonWriter, use this.
         * string json = JsonMapper.ToJson(exampleClass);
         *
         * //*/

        Debug.Log("deserialized:" + deserializedData);
    }
Example #32
0
    void Start()
    {
        ExampleSerializedClass serializedClass = new ExampleSerializedClass();

        JsonWriter writer = new JsonWriter();
        writer.PrettyPrint = true;

        JsonMapper.ToJson(serializedClass,writer);

        string json = writer.ToString();
        Debug.Log(json);

        // If you don't need a JsonWriter, use this.
        //string json = JsonMapper.ToJson(exampleClass);

        ExampleSerializedClass deserializedClass = JsonMapper.ToObject<ExampleSerializedClass>(savedJsonString);

        Debug.Log(deserializedClass.myString);
    }
Example #33
0
 private static string ToJson(object obj)
 {
     var jsonWriter = new JsonWriter { LowerCaseProperties = true };
     JsonMapper.ToJson(obj, jsonWriter);
     return jsonWriter.ToString();
 }
Example #34
0
	private static void writeConfig() {
		JsonWriter cfg = new JsonWriter();
		cfg.WriteObjectStart();
		cfg.WritePropertyName("scene");
		cfg.WriteArrayStart();
		GameObject[] arr = Selection.gameObjects;
		foreach (GameObject obj in arr) {
			writeObject(obj, ref cfg);
		}
		cfg.WriteArrayEnd();
		cfg.WriteObjectEnd();

		string filepath = folderName + "/scene.lightmap";
		if (File.Exists(filepath)) {
			File.Delete(filepath);
		}
		FileStream fs = new FileStream(filepath, FileMode.Create);
		BinaryWriter bw = new BinaryWriter(fs);
		bw.Write(cfg.ToString().ToCharArray());
		bw.Close();
		fs.Close();
		Debug.Log("Write Config:" + filepath);
	}
Example #35
0
 public string getJsonString (object obj)
 {
     //serialization
     JsonWriter writer = new JsonWriter ();
     writer.PrettyPrint = true;    
     JsonMapper.ToJson (obj, writer);    
 
     string json = writer.ToString ();
     return json;
 }
    public string getJsonString(object obj)
    {
        logMessage("object="+obj);

        //serialization
        JsonWriter writer = new JsonWriter();
        writer.PrettyPrint = true;
        JsonMapper.ToJson(obj,writer);

        string json = writer.ToString();
        logMessage("json="+json);
        return json;
    }