Thread: [Cppcms-users] json
Brought to you by:
artyom-beilis
From: Василий Т. <par...@gm...> - 2016-01-22 19:49:26
|
Hello everybody. Let's imagine jquery requests: 1) $.ajax({ method: "POST", url: "/test", contentType: "application/json", data: { "key": "test", "array": ["v1","v2","v3"] } }) jquery sends data in post form fields something like: key=test&array[]=v1&array[]=v2&array[]=v3 -> cppcms doesn't aggregate values into single json array via request().post("array") (neither "array", nor "array[]") 2) $.ajax({ method: "POST", url: "/test", contentType: "application/json", data: JSON.stringify({ "key": "test", "array": ["v1","v2","v3"] }) }) now we get content in json string format, but a) request().post() doesn't work; b) request doesn't have stream interface to fill cppcms::json::value, so we have to deal with raw_post_data(), which is not recommended. Do we have a convenient way to deal with json request? Thanks. |
From: Василий Т. <par...@gm...> - 2016-02-02 10:08:17
|
Hello Is there a way to deal with json arrays like {"units" : [{"id":1,"name":"test1"},{"id":2,"name":"test2"}]} ? I can't force cppcms to load such string into json without error. The only way is to use nested array as string value for a while :( |
From: Artyom B. <art...@ya...> - 2016-02-03 06:03:35
|
Please explain me what are you trying to do as it seems to me from the first glance a valid json. Artyom From: Василий Теркин <par...@gm...> To: cpp...@li... Sent: Tuesday, February 2, 2016 12:08 PM Subject: [Cppcms-users] json HelloIs there a way to deal with json arrays like{"units" : [{"id":1,"name":"test1"},{"id":2,"name":"test2"}]} ?I can't force cppcms to load such string into json without error.The only way is to use nested array as string value for a while :( ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 _______________________________________________ Cppcms-users mailing list Cpp...@li... https://lists.sourceforge.net/lists/listinfo/cppcms-users |
From: Artyom B. <art...@gm...> - 2016-02-03 06:26:40
|
Please explain me what are you trying to do as it seems to me from the first glance a valid json. Artyom P.S.: As usually I forgot to reply from GMail On Tue, Feb 2, 2016 at 12:08 PM, Василий Теркин <par...@gm...> wrote: > Hello > Is there a way to deal with json arrays like > {"units" : [{"id":1,"name":"test1"},{"id":2,"name":"test2"}]} > ? > I can't force cppcms to load such string into json without error. > The only way is to use nested array as string value for a while :( > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: Василий Т. <par...@gm...> - 2016-02-04 09:41:26
|
All the ways to deserialize this string (or alternative - with nested json inside array) to cppcms::json::value give undefined result. load() stops on '[' or something like that. (ver.1.0.5) 2016-02-03 9:26 GMT+03:00 Artyom Beilis <art...@gm...>: > Please explain me what are you trying to do as it seems to me from the > first glance a valid json. > > Artyom > P.S.: As usually I forgot to reply from GMail > > On Tue, Feb 2, 2016 at 12:08 PM, Василий Теркин <par...@gm...> > wrote: > > Hello > > Is there a way to deal with json arrays like > > {"units" : [{"id":1,"name":"test1"},{"id":2,"name":"test2"}]} > > ? > > I can't force cppcms to load such string into json without error. > > The only way is to use nested array as string value for a while :( > > > > > > > ------------------------------------------------------------------------------ > > Site24x7 APM Insight: Get Deep Visibility into Application Performance > > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > > Monitor end-to-end web transactions and take corrective actions now > > Troubleshoot faster and improve end-user experience. Signup Now! > > http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 > > _______________________________________________ > > Cppcms-users mailing list > > Cpp...@li... > > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: Artyom B. <art...@gm...> - 2016-02-04 09:46:40
|
Show the exact full code, it isn't clear what are you doing/trying to do. Artyom On Thu, Feb 4, 2016 at 11:41 AM, Василий Теркин <par...@gm...> wrote: > All the ways to deserialize this string (or alternative - with nested json > inside array) to cppcms::json::value give undefined result. > > load() stops on '[' or something like that. > > (ver.1.0.5) > > > 2016-02-03 9:26 GMT+03:00 Artyom Beilis <art...@gm...>: >> >> Please explain me what are you trying to do as it seems to me from the >> first glance a valid json. >> >> Artyom >> P.S.: As usually I forgot to reply from GMail >> >> On Tue, Feb 2, 2016 at 12:08 PM, Василий Теркин <par...@gm...> >> wrote: >> > Hello >> > Is there a way to deal with json arrays like >> > {"units" : [{"id":1,"name":"test1"},{"id":2,"name":"test2"}]} >> > ? >> > I can't force cppcms to load such string into json without error. >> > The only way is to use nested array as string value for a while :( >> > |
From: Василий Т. <par...@gm...> - 2016-02-04 13:40:49
|
Unbelivable.. i can't reproduce my recent problem anymore. I broke my head against the wall, but now the simplest code works well. I beg your pardon, Artyom, guys.. I need a vacation i guess.. 2016-02-04 12:46 GMT+03:00 Artyom Beilis <art...@gm...>: > Show the exact full code, it isn't clear what are you doing/trying to do. > > Artyom > > On Thu, Feb 4, 2016 at 11:41 AM, Василий Теркин <par...@gm...> > wrote: > > All the ways to deserialize this string (or alternative - with nested > json > > inside array) to cppcms::json::value give undefined result. > > > > load() stops on '[' or something like that. > > > > (ver.1.0.5) > > > > > > 2016-02-03 9:26 GMT+03:00 Artyom Beilis <art...@gm...>: > >> > >> Please explain me what are you trying to do as it seems to me from the > >> first glance a valid json. > >> > >> Artyom > >> P.S.: As usually I forgot to reply from GMail > >> > >> On Tue, Feb 2, 2016 at 12:08 PM, Василий Теркин <par...@gm...> > >> wrote: > >> > Hello > >> > Is there a way to deal with json arrays like > >> > {"units" : [{"id":1,"name":"test1"},{"id":2,"name":"test2"}]} > >> > ? > >> > I can't force cppcms to load such string into json without error. > >> > The only way is to use nested array as string value for a while :( > >> > > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: redred77 <red...@gm...> - 2016-01-22 22:14:38
|
How about sending stringify data per parameter if it is an array type? So plain key=text will be sent normally but array= will have return data of JSON.stringify. This will make you to deal with convenient request().post() as before. Thanks. 2016. 1. 23. 오전 4:50에 "Василий Теркин" <par...@gm...>님이 작성: > Hello everybody. > Let's imagine jquery requests: > 1) > $.ajax({ > method: "POST", > url: "/test", > contentType: "application/json", > data: { "key": "test", "array": ["v1","v2","v3"] } > }) > > jquery sends data in post form fields something like: > key=test&array[]=v1&array[]=v2&array[]=v3 > -> cppcms doesn't aggregate values into single json array via > request().post("array") > (neither "array", nor "array[]") > > 2) > $.ajax({ > method: "POST", > url: "/test", > contentType: "application/json", > data: JSON.stringify({ "key": "test", "array": ["v1","v2","v3"] }) > }) > > now we get content in json string format, but > a) request().post() doesn't work; > b) request doesn't have stream interface to fill cppcms::json::value, so > we have to deal with raw_post_data(), which is not recommended. > > Do we have a convenient way to deal with json request? > Thanks. > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |
From: mawan s. <ma...@gm...> - 2016-01-23 00:49:40
|
i think cppcms not handle it as array, waiting for explanation about dynamic field on client and send it to server. thanks On Sat, Jan 23, 2016 at 5:14 AM, redred77 <red...@gm...> wrote: > How about sending stringify data per parameter if it is an array type? So > plain key=text will be sent normally but array= will have return data of > JSON.stringify. > > This will make you to deal with convenient request().post() as before. > > Thanks. > 2016. 1. 23. 오전 4:50에 "Василий Теркин" <par...@gm...>님이 작성: > >> Hello everybody. >> Let's imagine jquery requests: >> 1) >> $.ajax({ >> method: "POST", >> url: "/test", >> contentType: "application/json", >> data: { "key": "test", "array": ["v1","v2","v3"] } >> }) >> >> jquery sends data in post form fields something like: >> key=test&array[]=v1&array[]=v2&array[]=v3 >> -> cppcms doesn't aggregate values into single json array via >> request().post("array") >> (neither "array", nor "array[]") >> >> 2) >> $.ajax({ >> method: "POST", >> url: "/test", >> contentType: "application/json", >> data: JSON.stringify({ "key": "test", "array": ["v1","v2","v3"] }) >> }) >> >> now we get content in json string format, but >> a) request().post() doesn't work; >> b) request doesn't have stream interface to fill cppcms::json::value, so >> we have to deal with raw_post_data(), which is not recommended. >> >> Do we have a convenient way to deal with json request? >> Thanks. >> >> >> ------------------------------------------------------------------------------ >> Site24x7 APM Insight: Get Deep Visibility into Application Performance >> APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month >> Monitor end-to-end web transactions and take corrective actions now >> Troubleshoot faster and improve end-user experience. Signup Now! >> http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 >> _______________________________________________ >> Cppcms-users mailing list >> Cpp...@li... >> https://lists.sourceforge.net/lists/listinfo/cppcms-users >> >> > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |
From: Василий Т. <par...@gm...> - 2016-01-23 19:35:55
|
Surely there are obvious solutions: prepare data on client side (if you can) or use unwanted raw_post_data(). I think that json request data should be handled in a simpler way. Or i didn't find the way. 2016-01-23 1:14 GMT+03:00 redred77 <red...@gm...>: > How about sending stringify data per parameter if it is an array type? So > plain key=text will be sent normally but array= will have return data of > JSON.stringify. > > This will make you to deal with convenient request().post() as before. > > Thanks. > 2016. 1. 23. 오전 4:50에 "Василий Теркин" <par...@gm...>님이 작성: > >> Hello everybody. >> Let's imagine jquery requests: >> 1) >> $.ajax({ >> method: "POST", >> url: "/test", >> contentType: "application/json", >> data: { "key": "test", "array": ["v1","v2","v3"] } >> }) >> >> jquery sends data in post form fields something like: >> key=test&array[]=v1&array[]=v2&array[]=v3 >> -> cppcms doesn't aggregate values into single json array via >> request().post("array") >> (neither "array", nor "array[]") >> >> 2) >> $.ajax({ >> method: "POST", >> url: "/test", >> contentType: "application/json", >> data: JSON.stringify({ "key": "test", "array": ["v1","v2","v3"] }) >> }) >> >> now we get content in json string format, but >> a) request().post() doesn't work; >> b) request doesn't have stream interface to fill cppcms::json::value, so >> we have to deal with raw_post_data(), which is not recommended. >> >> Do we have a convenient way to deal with json request? >> Thanks. >> >> >> ------------------------------------------------------------------------------ >> Site24x7 APM Insight: Get Deep Visibility into Application Performance >> APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month >> Monitor end-to-end web transactions and take corrective actions now >> Troubleshoot faster and improve end-user experience. Signup Now! >> http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 >> _______________________________________________ >> Cppcms-users mailing list >> Cpp...@li... >> https://lists.sourceforge.net/lists/listinfo/cppcms-users >> >> > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |
From: Artyom B. <art...@gm...> - 2016-01-23 21:07:07
|
> Let's imagine jquery requests: > 1) > $.ajax({ > method: "POST", > url: "/test", > contentType: "application/json", > data: { "key": "test", "array": ["v1","v2","v3"] } > }) > > jquery sends data in post form fields something like: > key=test&array[]=v1&array[]=v2&array[]=v3 > -> cppcms doesn't aggregate values into single json array via > request().post("array") > (neither "array", nor "array[]") > It shouldn't. If you test application/json than you should parse it as JSON > b) request doesn't have stream interface to fill cppcms::json::value, so we > have to deal with raw_post_data(), which is not recommended. > Who told you raw_post_data() isn't recommended? > Do we have a convenient way to deal with json request? You can just create a temporary istream from the post data and parse the json - that is what json-rpc API does. Also CppCMS 1.1 introduced json::parse from range of [char const *,char const *) > Thanks. > Artyom |
From: Василий Т. <par...@gm...> - 2016-01-23 22:10:25
|
> > > Let's imagine jquery requests: > > 1) > > $.ajax({ > > method: "POST", > > url: "/test", > > contentType: "application/json", > > data: { "key": "test", "array": ["v1","v2","v3"] } > > }) > > > > jquery sends data in post form fields something like: > > key=test&array[]=v1&array[]=v2&array[]=v3 > > -> cppcms doesn't aggregate values into single json array via > > request().post("array") > > (neither "array", nor "array[]") > > > It shouldn't. If you test application/json than you should parse it as JSON > I haven't dig into jquery - this is what i've got with it with such settings. I was very surpised to see form post fields in place of json with contentType: "application/json" > > b) request doesn't have stream interface to fill cppcms::json::value, so > we > > have to deal with raw_post_data(), which is not recommended. > > > > Who told you raw_post_data() isn't recommended? > My bad. It looks like that was my own decision because of conditional behaviour of this method. > > > Do we have a convenient way to deal with json request? > > You can just create a temporary istream from the post data and parse > the json - that is what json-rpc API does. > This is what i do for now. > Also CppCMS 1.1 introduced json::parse from range of [char const *,char > const *) > > Thanks a lot, i'll try this one. > > Thanks. > > > > Artyom > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |