@@ -101,24 +101,28 @@ void ffGeneratePowerAdapterJsonResult(FF_MAYBE_UNUSED FFPowerAdapterOptions* opt
101101 if (error )
102102 {
103103 yyjson_mut_obj_add_str (doc , module , "error" , error );
104+ return ;
104105 }
105- else if (results .length == 0 )
106+
107+ yyjson_mut_val * arr = yyjson_mut_obj_add_arr (doc , module , "result" );
108+ FF_LIST_FOR_EACH (FFPowerAdapterResult , item , results )
106109 {
107- yyjson_mut_obj_add_str (doc , module , "error" , "No power adapters found" );
110+ yyjson_mut_val * obj = yyjson_mut_arr_add_obj (doc , arr );
111+ yyjson_mut_obj_add_strbuf (doc , obj , "description" , & item -> description );
112+ yyjson_mut_obj_add_strbuf (doc , obj , "manufacturer" , & item -> manufacturer );
113+ yyjson_mut_obj_add_strbuf (doc , obj , "modelName" , & item -> modelName );
114+ yyjson_mut_obj_add_strbuf (doc , obj , "name" , & item -> name );
115+ yyjson_mut_obj_add_strbuf (doc , obj , "serial" , & item -> serial );
116+ yyjson_mut_obj_add_int (doc , obj , "watts" , item -> watts );
108117 }
109- else
118+
119+ FF_LIST_FOR_EACH (FFPowerAdapterResult , item , results )
110120 {
111- yyjson_mut_val * arr = yyjson_mut_obj_add_arr (doc , module , "result" );
112- FF_LIST_FOR_EACH (FFPowerAdapterResult , item , results )
113- {
114- yyjson_mut_val * obj = yyjson_mut_arr_add_obj (doc , arr );
115- yyjson_mut_obj_add_strbuf (doc , obj , "description" , & item -> description );
116- yyjson_mut_obj_add_strbuf (doc , obj , "manufacturer" , & item -> manufacturer );
117- yyjson_mut_obj_add_strbuf (doc , obj , "modelName" , & item -> modelName );
118- yyjson_mut_obj_add_strbuf (doc , obj , "name" , & item -> name );
119- yyjson_mut_obj_add_strbuf (doc , obj , "serial" , & item -> serial );
120- yyjson_mut_obj_add_int (doc , obj , "watts" , item -> watts );
121- }
121+ ffStrbufDestroy (& item -> manufacturer );
122+ ffStrbufDestroy (& item -> description );
123+ ffStrbufDestroy (& item -> modelName );
124+ ffStrbufDestroy (& item -> name );
125+ ffStrbufDestroy (& item -> serial );
122126 }
123127}
124128
0 commit comments