c# - What Are Some Options To Convert Url-Encoded Form Data to JSON in .Net -


i have web request sending server data in format application/x-www-form-urlencoded. convert application/json.

example:

url-encoded form data:

property1=a&property2=b&property3%5b0%5d%5bsubproperty1%5d=a&property3%5b0%5d%5bsubproperty2%5d=b&property3%5b1%5d%5bsubproperty1%5d=c&property3%5b1%5d%5bsubproperty2%5d=d 

pretty version:

property1=a property2=b property3[0][subproperty1]=a property3[0][subproperty2]=b property3[1][subproperty1]=c property3[1][subproperty2]=d 

the above data needs converted following json data:

{     property1: "a",     property2: "b",     property3: [         { subproperty1: "a", subproperty2: "b" },         { subproperty1: "c", subproperty2: "d" }] } 

question:

are there free tools capable of doing this? have not been able find myself , if exist, i'd rather consume them writing 1 myself, if comes that, will.

a c#/.net solution preferred.

i've written utility class parsing query strings , form data. it's available at:

https://gist.github.com/peteroupc/5619864

example:

// example query string question string test="property1=a&property2=b&property3%5b0%5d%5bsubproperty1%5d=a&property3%5b0%5d%5bsubproperty2%5d=b&property3%5b1%5d%5bsubproperty1%5d=c&property3%5b1%5d%5bsubproperty2%5d=d"; // convert query string json-friendly dictionary var o=querystringhelper.querystringtodict(test); // convert dictionary json string using json.net // library <http://json.codeplex.com/> var json=jsonconvert.serializeobject(o); // output json string console console.writeline(json); 

let me know if works you.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -