Hi I am having problems converting lists to Json.
this is my code:
:- json_object schedule_result(room:string, day:string, room_agenda:list(schedule_segment), lnaesthetist:list(schedule_doctors), ldoctors:list(schedule_doctors), lcleaners:list(schedule_doctors), stime:integer).
:- json_object schedule_doctors(doctor:string, doctor_agenda:list(schedule_segment)).
:- json_object schedule_segment(start=integer, end=integer, opcode=string).
:- http_handler('/bestsolution', handle_get_better_solution, [ ]).
handle_get_better_solution(Request) :-
http_read_json(Request, JSON, [json_object(dict)]),
Room = JSON.room,
Day = JSON.day,
obtain_better_sol(or1,20241028,LRooms,LAnesthetist,LDoctors,LCleaners,Time),
convert_segment_list_to_json(LRooms, JsonLRooms),
convert_doctors_list_to_json(LAnesthetist, JsonLAnesthetist),
convert_doctors_list_to_json(LDoctor, JsonLDoctor),
convert_doctors_list_to_json(LCleaner, JsonLCleaner),
R = schedule_result(Room, Day, JsonLRooms, JsonLAnesthetist, JsonLDoctor,JsonLCleaner, Time),
prolog_to_json(R, JSONObject),
reply_json(JSONObject, [json_object(dict)]).
convert_segment_list_to_json([], []).
convert_segment_list_to_json([(Start, End, OpCode)|Tail], [Reply | JsonArray]) :-
Reply = schedule_segment(Start, End, OpCode),
convert_segment_list_to_json(Tail, JsonArray).
convert_doctors_list_to_json([], []).
convert_doctors_list_to_json([(Doctor, Agenda)| Tail], [Reply | JsonArray]) :-
convert_segment_list_to_json(Agenda, JsonAgenda),
Reply = schedule_doctors(Doctor, JsonAgenda),
convert_doctors_list_to_json(Tail, JsonArray).
I tried changing the json_objects to this:
:- json_object schedule_result(room:string, day:string, room_agenda:list(schedule_segment), lnaesthetist:string, ldoctors:string, lcleaners:string, stime:integer).
:- json_object schedule_doctors(doctor:string, doctor_agenda:list(schedule_segment)).
:- json_object schedule_segment(start=integer, end=integer, opcode=string).
for debugging and the room_agenda was working. The problem is when i trt to use list(schedule_doctors).
When I try it i receive this error message:
{
"code": 500,
"message": "Type error: `json_term' expected, found `schedule_doctors(a003,[schedule_segment(1060,1179,so100003)])' (a compound)