Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Deserialise complicated Jason data

Deserialise complicated Jason data

Scheduled Pinned Locked Moved C#
csharpjavascriptdesignjsonhelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndieDu
    wrote on last edited by
    #1

    Dear all, I have this jason data that ready to be serialised: (Indention added for readability)

    {"Error":"",
    "UserMeasurements":
    [{ "MeasurementName":"BloodPressure",
    "ClinicalDatas":
    [{"Name":"Systolic",
    "Unit":"mmHg ",
    "ClinicalDataPoints":[[1304197968110,149],[1304290213920,145],[1304369712717,159],[1304459900650,160],
    [1304542964530,176],[1304564292340,147],[1304649916767,141],[1304726125653,139],[1304826583873,156],
    [1304880946500,167],[1305069333890,152]]},
    {"Name":"Diastolic",
    "Unit":"mmHg ",
    "ClinicalDataPoints":[[1304197968220,129],[1304290215047,92],[1304369712763,91],[1304459900900,105],
    [1304542965530,83],[1304564292403,103],[1304649916797,81],[1304726125687,133],[1304826584000,85],
    [1304880946547,108],[1305069334890,89]]},
    {"Name":"Mean Blood Pressure",
    "Unit":"mmHg ",
    "ClinicalDataPoints":[]}
    ]
    }
    ]
    }";

    and I have these c# code to deserialised it:

    namespace Json
    {
    public partial class _Default : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    JavaScriptSerializer js = new JavaScriptSerializer();
    string test = "{\"Error\":\"\",\"UserMeasurements\":[{\"MeasurementName\":\"BloodPressure\",\"ClinicalDatas\":[{\"Name\":\"Systolic\",\"Unit\":\"mmHg \",\"ClinicalDataPoints\":[[1304197968110,149],[1304290213920,145],[1304369712717,159],[1304459900650,160],[1304542964530,176],[1304564292340,147],[1304649916767,141],[1304726125653,139],[1304826583873,156],[1304880946500,167],[1305069333890,152]]},{\"Name\":\"Diastolic\",\"Unit\":\"mmHg \",\"ClinicalDataPoints\":[[1304197968220,129],[1304290215047,92],[1304369712763,91],[1304459900900,105],[1304542965530,83],[1304564292403,103],[1304649916797,81],[1304726125687,133],[1304826584000,85],[1304880946547,108],[1305069334890,89]]},{\"Name\":\"Mean Blood Pressure\",\"Unit\":

    B B 2 Replies Last reply
    0
    • A AndieDu

      Dear all, I have this jason data that ready to be serialised: (Indention added for readability)

      {"Error":"",
      "UserMeasurements":
      [{ "MeasurementName":"BloodPressure",
      "ClinicalDatas":
      [{"Name":"Systolic",
      "Unit":"mmHg ",
      "ClinicalDataPoints":[[1304197968110,149],[1304290213920,145],[1304369712717,159],[1304459900650,160],
      [1304542964530,176],[1304564292340,147],[1304649916767,141],[1304726125653,139],[1304826583873,156],
      [1304880946500,167],[1305069333890,152]]},
      {"Name":"Diastolic",
      "Unit":"mmHg ",
      "ClinicalDataPoints":[[1304197968220,129],[1304290215047,92],[1304369712763,91],[1304459900900,105],
      [1304542965530,83],[1304564292403,103],[1304649916797,81],[1304726125687,133],[1304826584000,85],
      [1304880946547,108],[1305069334890,89]]},
      {"Name":"Mean Blood Pressure",
      "Unit":"mmHg ",
      "ClinicalDataPoints":[]}
      ]
      }
      ]
      }";

      and I have these c# code to deserialised it:

      namespace Json
      {
      public partial class _Default : System.Web.UI.Page
      {
      protected void Page_Load(object sender, EventArgs e)
      {
      JavaScriptSerializer js = new JavaScriptSerializer();
      string test = "{\"Error\":\"\",\"UserMeasurements\":[{\"MeasurementName\":\"BloodPressure\",\"ClinicalDatas\":[{\"Name\":\"Systolic\",\"Unit\":\"mmHg \",\"ClinicalDataPoints\":[[1304197968110,149],[1304290213920,145],[1304369712717,159],[1304459900650,160],[1304542964530,176],[1304564292340,147],[1304649916767,141],[1304726125653,139],[1304826583873,156],[1304880946500,167],[1305069333890,152]]},{\"Name\":\"Diastolic\",\"Unit\":\"mmHg \",\"ClinicalDataPoints\":[[1304197968220,129],[1304290215047,92],[1304369712763,91],[1304459900900,105],[1304542965530,83],[1304564292403,103],[1304649916797,81],[1304726125687,133],[1304826584000,85],[1304880946547,108],[1305069334890,89]]},{\"Name\":\"Mean Blood Pressure\",\"Unit\":

      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #2

      The property appears to be called 'ClinicalDatas' (not UserClinicalDatas) in the JSON. Regarding the names, 'data' is already plural, so using 'datas' just looks wrong. If you are in charge of both ends of this serialisation you should change that.

      A 1 Reply Last reply
      0
      • B BobJanova

        The property appears to be called 'ClinicalDatas' (not UserClinicalDatas) in the JSON. Regarding the names, 'data' is already plural, so using 'datas' just looks wrong. If you are in charge of both ends of this serialisation you should change that.

        A Offline
        A Offline
        AndieDu
        wrote on last edited by
        #3

        right on the spot, Bob, and amazingly, i didnt spot out this subtle thing, thanks heaps anyway.

        1 Reply Last reply
        0
        • A AndieDu

          Dear all, I have this jason data that ready to be serialised: (Indention added for readability)

          {"Error":"",
          "UserMeasurements":
          [{ "MeasurementName":"BloodPressure",
          "ClinicalDatas":
          [{"Name":"Systolic",
          "Unit":"mmHg ",
          "ClinicalDataPoints":[[1304197968110,149],[1304290213920,145],[1304369712717,159],[1304459900650,160],
          [1304542964530,176],[1304564292340,147],[1304649916767,141],[1304726125653,139],[1304826583873,156],
          [1304880946500,167],[1305069333890,152]]},
          {"Name":"Diastolic",
          "Unit":"mmHg ",
          "ClinicalDataPoints":[[1304197968220,129],[1304290215047,92],[1304369712763,91],[1304459900900,105],
          [1304542965530,83],[1304564292403,103],[1304649916797,81],[1304726125687,133],[1304826584000,85],
          [1304880946547,108],[1305069334890,89]]},
          {"Name":"Mean Blood Pressure",
          "Unit":"mmHg ",
          "ClinicalDataPoints":[]}
          ]
          }
          ]
          }";

          and I have these c# code to deserialised it:

          namespace Json
          {
          public partial class _Default : System.Web.UI.Page
          {
          protected void Page_Load(object sender, EventArgs e)
          {
          JavaScriptSerializer js = new JavaScriptSerializer();
          string test = "{\"Error\":\"\",\"UserMeasurements\":[{\"MeasurementName\":\"BloodPressure\",\"ClinicalDatas\":[{\"Name\":\"Systolic\",\"Unit\":\"mmHg \",\"ClinicalDataPoints\":[[1304197968110,149],[1304290213920,145],[1304369712717,159],[1304459900650,160],[1304542964530,176],[1304564292340,147],[1304649916767,141],[1304726125653,139],[1304826583873,156],[1304880946500,167],[1305069333890,152]]},{\"Name\":\"Diastolic\",\"Unit\":\"mmHg \",\"ClinicalDataPoints\":[[1304197968220,129],[1304290215047,92],[1304369712763,91],[1304459900900,105],[1304542965530,83],[1304564292403,103],[1304649916797,81],[1304726125687,133],[1304826584000,85],[1304880946547,108],[1305069334890,89]]},{\"Name\":\"Mean Blood Pressure\",\"Unit\":

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          Try a tool for generating your classes from the Json data, e.g. http://json2csharp.com/[^]. That will prevent typos.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups