locked
JayRock JSON/VB.NET RRS feed

  • Question

  • User51168061 posted

    Hello All,

    I just started looking into JSON and managed to create a JSON object.

    Dim objjson1 As New Jayrock.Json.JsonTextWriter
    objjson1.WriteStartObject()
    objjson1.WriteMember("First Name")
    objjson1.WriteString("John")
    objjson1.WriteMember("Last Name")
    objjson1.WriteString("Gear")
    objjson1.WriteMember("DOB")
    objjson1.WriteString("05/05/1905")
    objjson1.WriteEndObject()

    This displays a string that looks like -

    {"First Name":"John","Last Name":"Gear","DOB":"05/05/1905"}


    My question would be, how can I use the objjson1 object and pull out relevant information by doing something like this:

    objjson1.("First Name") and this would return John. Thoughts? Thanks for any help!

    - Gabe

    Tuesday, April 2, 2013 8:47 PM

Answers

All replies

  • User-1137493631 posted

    you have to use Json Text Reader to do that

    JsonTextReader reader = new JsonTextReader(new StringReader(json));

    please try this link 

    http://james.newtonking.com/projects/json/help/index.html?topic=html/ReadingWritingJSON.htm



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 2, 2013 8:59 PM
  • User51168061 posted

    Thank you. Appreciate the help! I'll give that a shot.

    - G

    Tuesday, April 2, 2013 9:09 PM
  • User51168061 posted

    Thanks for the link. I played around with it and it looks like this may be what I am trying to do:

    create an object and then reference certain properties from that object. You wouldn't know how to do this in VB.NET or point me in the right direction? Thanks again.

    1JObject o = new JObject(
     2  new JProperty("Name", "John Smith"),
     3  new JProperty("BirthDate", new DateTime(1983, 3, 20))
     4  );
     5
     6JsonSerializer serializer = new JsonSerializer();
     7Person p = (Person)serializer.Deserialize(new JTokenReader(o), typeof(Person));
     8
     9Console.WriteLine(p.Name);
    10// John Smith
    Tuesday, April 2, 2013 10:29 PM