Responding with a JSON object in Node.js (converting object/array to JSON string)

前端 未结 6 1086
广开言路
广开言路 2020-12-04 08:01

I\'m a newb to back-end code and I\'m trying to create a function that will respond to me a JSON string. I currently have this from an example

function rando         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 08:55

    var objToJson = { };
    objToJson.response = response;
    response.write(JSON.stringify(objToJson));
    

    If you alert(JSON.stringify(objToJson)) you will get {"response":"value"}

提交回复
热议问题