Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

deserialize json newtonsoft

        private StoreAndLoadMe DeserializeMe()
        {
            using (StreamReader file = File.OpenText(fileName))
            using (JsonTextReader reader = new JsonTextReader(file))
            {
                JObject obj = (JObject)JToken.ReadFrom(reader);
                return JsonConvert.DeserializeObject<StoreAndLoadMe>(obj.ToString());
            }
        }

        private void SerializeMe(StoreAndLoadMe slm)
        {
            var json = JsonConvert.SerializeObject(slm, Formatting.Indented);
            using (StreamWriter writer  = File.CreateText(fileName))
                writer.Write(json);
        }

// Add Attribute to StoreAndLoadMe class:
    [JsonObject]
    internal class StoreAndLoadMe
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #deserialize #json #newtonsoft
ADD COMMENT
Topic
Name
3+9 =