logo
down
shadow

Complex JSON to Java class


Complex JSON to Java class

By : user2950007
Date : November 17 2020, 04:28 AM
I wish did fix the issue. Use a JSON beautifier (like http://jsonformatter.curiousconcept.com/) so you can see better what's in there. Then, create classes, like this:
code :
class article {
    String publish_date;
    String title;
    ...


Share : facebook icon twitter icon
convert complex json to c# class

convert complex json to c# class


By : VictorG
Date : March 29 2020, 07:55 AM
To fix the issue you can do Here's a working dotNet Fiddle that deserializes the Values List. https://dotnetfiddle.net/7P2em6
Wait few seconds when you load the fiddle and notice the output in the Console window. The code should be self-explanatory, but let me know if you need help.
code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Web;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

    // SO Question: http://stackoverflow.com/questions/27132887/
    // This (my) Answer: 
    // Author: Shiva Manjunath
    // SO Profile: http://stackoverflow.com/users/325521/shiva
public class Program
{   
    public static void Main()
    {

       string jsonString = @"{
  ""metadata"": {
    ""columnGrouping"": [
      ""area"",
      ""metricType"",
      ""period"",
      ""valueType""
    ],
    ""rowGrouping"": []
  },
  ""columns"": [
    {
      ""area"": {
        ""identifier"": ""E31000040"",
        ""label"": ""Gtr Manchester Fire"",
        ""altLabel"": ""Gtr Manchester Fire"",
        ""isSummary"": false
      },
      ""metricType"": {
        ""identifier"": ""948"",
        ""label"": ""Accidental dwelling fires"",
        ""altLabel"": ""Accidental dwelling fires"",
        ""isSummary"": false
      },
      ""period"": {
        ""identifier"": ""fq_Q1_2013_14"",
        ""label"": ""2013/14 Q1"",
        ""altLabel"": ""2013/14 Q1"",
        ""isSummary"": false
      },
      ""valueType"": {
        ""identifier"": ""raw"",
        ""label"": ""Raw value"",
        ""isSummary"": false
      }
    },
    {
      ""area"": {
        ""identifier"": ""E31000040"",
        ""label"": ""Gtr Manchester Fire"",
        ""altLabel"": ""Gtr Manchester Fire"",
        ""isSummary"": false
      },
      ""metricType"": {
        ""identifier"": ""948"",
        ""label"": ""Accidental dwelling fires"",
        ""altLabel"": ""Accidental dwelling fires"",
        ""isSummary"": false
      },
      ""period"": {
        ""identifier"": ""fq_Q2_2013_14"",
        ""label"": ""2013/14 Q2"",
        ""altLabel"": ""2013/14 Q2"",
        ""isSummary"": false
      },
      ""valueType"": {
        ""identifier"": ""raw"",
        ""label"": ""Raw value"",
        ""isSummary"": false
      }
    },
    {
      ""area"": {
        ""identifier"": ""E31000040"",
        ""label"": ""Gtr Manchester Fire"",
        ""altLabel"": ""Gtr Manchester Fire"",
        ""isSummary"": false
      },
      ""metricType"": {
        ""identifier"": ""948"",
        ""label"": ""Accidental dwelling fires"",
        ""altLabel"": ""Accidental dwelling fires"",
        ""isSummary"": false
      },
      ""period"": {
        ""identifier"": ""fq_Q3_2013_14"",
        ""label"": ""2013/14 Q3"",
        ""altLabel"": ""2013/14 Q3"",
        ""isSummary"": false
      },
      ""valueType"": {
        ""identifier"": ""raw"",
        ""label"": ""Raw value"",
        ""isSummary"": false
      }
    },
    {
      ""area"": {
        ""identifier"": ""E31000040"",
        ""label"": ""Gtr Manchester Fire"",
        ""altLabel"": ""Gtr Manchester Fire"",
        ""isSummary"": false
      },
      ""metricType"": {
        ""identifier"": ""948"",
        ""label"": ""Accidental dwelling fires"",
        ""altLabel"": ""Accidental dwelling fires"",
        ""isSummary"": false
      },
      ""period"": {
        ""identifier"": ""fq_Q4_2013_14"",
        ""label"": ""2013/14 Q4"",
        ""altLabel"": ""2013/14 Q4"",
        ""isSummary"": false
      },
      ""valueType"": {
        ""identifier"": ""raw"",
        ""label"": ""Raw value"",
        ""isSummary"": false
      }
    }
  ],
  ""rows"": [
    {
      ""values"": [
        {
          ""source"": 515.0,
          ""value"": 515.0,
          ""formatted"": ""515"",
          ""format"": ""#,##0"",
          ""publicationStatus"": ""Published""
        },
        {
          ""source"": 264.0,
          ""value"": 264.0,
          ""formatted"": ""264"",
          ""format"": ""#,##0"",
          ""publicationStatus"": ""Published""
        },
        {
          ""source"": 254.0,
          ""value"": 254.0,
          ""formatted"": ""254"",
          ""format"": ""#,##0"",
          ""publicationStatus"": ""Published""
        },
        {
          ""source"": 455.0,
          ""value"": 455.0,
          ""formatted"": ""455"",
          ""format"": ""#,##0"",
          ""publicationStatus"": ""Published""
        }
      ]
    }
  ]
}";

      Console.WriteLine("Begin JSON Deserialization\n");

      var rootObject = JsonConvert.DeserializeObject<RootObject>(jsonString);
      var rows = rootObject.rows; 
      int rowCounter = 1;
      foreach (Row oneRow in rows)
      {
          Console.WriteLine("Row: " + rowCounter);
          int valueCounter = 1;
          foreach(Value oneValue in oneRow.values)
          {
            Console.WriteLine("    Value: " + valueCounter);              
            Console.WriteLine("        source: " + oneValue.source);
            Console.WriteLine("        value: " + oneValue.value);
            Console.WriteLine("        formatted: " + oneValue.formatted);
            Console.WriteLine("        publicationStatus: " + oneValue.publicationStatus);                
            valueCounter++;
          }
          rowCounter++;
      }

      Console.WriteLine("\nEnd JSON Deserialization");

}
}

public class Metadata
{
    public List<string> columnGrouping { get; set; }
}

public class Area
{
    public string identifier { get; set; }
    public string label { get; set; }
    public string altLabel { get; set; }
    public bool isSummary { get; set; }
}

public class MetricType
{
    public string identifier { get; set; }
    public string label { get; set; }
    public string altLabel { get; set; }
    public bool isSummary { get; set; }
}

public class Period
{
    public string identifier { get; set; }
    public string label { get; set; }
    public string altLabel { get; set; }
    public bool isSummary { get; set; }
}

public class ValueType
{
    public string identifier { get; set; }
    public string label { get; set; }
    public bool isSummary { get; set; }
}

public class Column
{
    public Area area { get; set; }
    public MetricType metricType { get; set; }
    public Period period { get; set; }
    public ValueType valueType { get; set; }
}

public class Value
{
    public double source { get; set; }
    public double value { get; set; }
    public string formatted { get; set; }
    public string format { get; set; }
    public string publicationStatus { get; set; }
}

public class Row
{
    public List<Value> values { get; set; }
}

public class RootObject
{
    public Metadata metadata { get; set; }
    public List<Column> columns { get; set; }
    public List<Row> rows { get; set; }
}
Create a Java POJO class for a Complex Json hierarchy

Create a Java POJO class for a Complex Json hierarchy


By : user2962783
Date : March 29 2020, 07:55 AM
will be helpful for those in need I suggest you to use one of online services to generate POJOs from JSON, e.g. I'd prefer to use this one. Simply copy your JSON, select "Source type" as JSON and press preview or jar. In case of jar just unpack it with any zip/unzip program and copy files in your project. That's it.
C# JSON deserialize into complex class

C# JSON deserialize into complex class


By : VeryByte
Date : March 29 2020, 07:55 AM
Any of those help I have a JSON like this , Your custom classes should be like it.
code :
 public class Application
    {
        public string Office { get; set; }
        public List<string> LogPath { get; set; }
    }

    public class MailSettings
    {
        public string MailTo { get; set; }
        public string MailSubject { get; set; }
    }

    public class RootObject
    {
        public List<Application> Application { get; set; }
        public MailSettings MailSettings { get; set; }
    }
Map Complex Json to Pojo Class

Map Complex Json to Pojo Class


By : Knight
Date : March 29 2020, 07:55 AM
around this issue Your PojoClass has to follow the structure of the JSON that your are receiving and have the fields that your are interested (or all of them).
For the first level class:
code :
public class PojoClass {
    private Customer customer;
    private String status;
    ...
}
public class Customer {
    public String id;
    public CI ci;
    public CustData custData;
    ...
}
Deriving Complex class from TVector2 class: "No matching function for call to Complex::Complex()"

Deriving Complex class from TVector2 class: "No matching function for call to Complex::Complex()"


By : FJD
Date : March 29 2020, 07:55 AM
I wish this helpful for you When writing Complex c; You are trying to invoke the constructor Complex::Complex (), which is undefined in your Complex class, since the only available constructor takes 2 arguments Complex::Complex (double, double).
So, there are couple of ways to solve such a problem:
code :
Complex c (0, 0);
class Complex : public TVector2 {
public:
    Complex (double re, double im): TVector2 (re, im) {}
    Complex (): TVector2 (0, 0) {}

protected:
    double m_re;
    double m_im;
};
class Complex : public TVector2 {
public:
    Complex (double re, double im): TVector2 (re, im) {}
    Complex (): Complex (0, 0) {}

protected:
    double m_re;
    double m_im;
};
class Complex : public TVector2 {
public:
    Complex (double re = 0, double im = 0): TVector2 (re, im) {}

protected:
    double m_re;
    double m_im;
};
class Complex {
public:
    Complex (): m_re (0), m_im (0) {}
    Complex (double re, double im): m_re (re), m_im (im) {}

protected:
    double m_re;
    double m_im;
};
class Complex {
public:
    Complex (double re, double im): m_re (re), m_im (im) {}
    Complex (): Complex (0, 0) {}

protected:
    double m_re;
    double m_im;
};
class Complex {
public:
    Complex (double re = 0, double im = 0): m_re (re), m_im (im) {}

protected:
    double m_re;
    double m_im;
};
Related Posts Related Posts :
  • Android Studio gradle build failed for hello world app
  • Slide a layout up from bottom of screen
  • Play HTML5 video in iOS/Android native media player
  • How to rescale a bitmap file in android?
  • No view found for id 0x for fragment after rotation?
  • Define different themable styles to the same widget types
  • ProGuard not working in my app
  • FragmentTransaction from BaseAdapter
  • Connecting multiple devices in a Wifi Direct group
  • Why TabActivity is deprecated in android
  • How to capture low resolution picture using android camera
  • android preferenceactivity padding in landscape orientation
  • How can I store cookie in webview?
  • Passing variables from one activity to another
  • Create Multicolored Pie Chart in Android Studio
  • how to kill progress dialog in android
  • Show Error on the tip of the Edit Text Android
  • How do I use getWindowManager() by another java file
  • fetching images from gallery on android phones with internal storage
  • How to discover devices like Google TV and Nexus-Q using MediaRoute API on Android?
  • "Unfortunately your app stopped working"- Facebook Integration for Android
  • How to animate button in android?
  • Resource Not Found Exception in class without context or activity
  • Launching Android Netflix App And Passing Video Id
  • Making a Phone Call with a Number Extension
  • NullPointerException at BoringLayout.isBoring is anything but boring
  • java.lang.RuntimeException: Unable to get provider
  • Testing custom Views with Robolectric
  • tools:listheader doesn't work although tools:listitem does
  • oppo, vivo app kill notification not coming in android fcm
  • OnClick Method could not function correctly with if else statement
  • Best method to download image from url in Android
  • How can I open Drawer Layout moving all the view and not just slide over?
  • how to show profile pictures of friends in a list view?
  • Creating TimePickerDialog with custom style in Android
  • Android 2.3.6 support library v7 option menu is missing
  • need of vblank in Display subssytem
  • Android MP4 stream - Video cannot be played
  • FastAdapter: Undo button does not show up after swipe
  • What are reasons to pass getActivity as the LifecycleOwner to the LiveData's observe method in a fragment?
  • Implement Face Recognition in Android
  • Titanium studio cannot run "titanium" command in terminal
  • How to execute command line ffmpeg commands programatically in android?
  • Make Android List Items clickable with each item pointing to a different link
  • listview runs successfully, but nothing is display in emulator
  • How to zoom in a bitmap with high resolution?
  • Passing listView data through intent
  • Google map route direction show by arrows in android v2
  • how to start "uiautomator test run" from android code?
  • Proguard in Android Library
  • Alarm Clock from GIT - Gives error - Android
  • Mock injection using Mockito - Android
  • Get Bitmap from universal image loader
  • Unable to include custom font in android
  • Basics on using logcat in Android development
  • Android: Clear cache programmatically
  • Android: pass object without serialization
  • Can not scroll and click item on gridview inside scrollview
  • Android device keeps disconnecting from adb / eclipse
  • Volley cannot create cache directory. Could not clean up file
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org