Forum > General

TJSONObject : Whether objects can be directly transferred to json

(1/1)

Jzhen:

--- Quote ---   Student student = new Student();
   student.setId(1);
   student.setAge("20");
   student.setName("jno");
   System.out.println(JSON.toJSON(student));
 
   String stuString = JSONObject.toJSONString(student);

--- End quote ---

jsonObject.ToString or jsonObject.ToJSON cannot implement such conversion. What should i do?

paweld:
https://wiki.lazarus.freepascal.org/Streaming_JSON

PierceNg:
https://wiki.freepascal.org/LGenerics#Exporting_structures_to_JSON_format

Jzhen:

--- Quote from: paweld on February 09, 2023, 10:44:38 am ---https://wiki.lazarus.freepascal.org/Streaming_JSON

--- End quote ---

This is a record. Can it be implemented without changing the data type? I think it needs to inherit TPersistent. This modification may not be accepted by the company.

Jzhen:

--- Quote from: PierceNg on February 09, 2023, 11:58:15 am ---https://wiki.freepascal.org/LGenerics#Exporting_structures_to_JSON_format

--- End quote ---


I still view it in the watch list

Navigation

[0] Message Index

Go to full version