M
M
Maxim2017-07-17 23:36:52
Angular
Maxim, 2017-07-17 23:36:52

What is the correct way to write a class to represent data?

For example, I have JSON:
{
"name": "Tom",
"age": 24
}
I get this file with a GET request, and to represent the data I have a class
export class User {
name: string;
age: number
}
But what if I'm requesting not a small file that I wrote myself in two lines, but an API with a weather forecast for a week, how do I write this class in this case? Given that there are nested arrays and objects. Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2017-07-17
@american6oy

and what for to you a class for representation of the data?

export interface User {
  name: string,
  age: number,
  radioSettings: UserRadioSettings
}

/* ---------------------- */

export interface UserRadioSettings {
  volumeLevel: number,
  defaultStation: string
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question