java code corresponding to Newtonsoft.Json.JsonConvert.SerializeObject(Object source,Newtonsoft.Json.JsonSerializerSettings()) in .net? -


i have code in .net serializes request json format ... code this.

  var ops = new newtonsoft.json.jsonserializersettings();   ops.nullvaluehandling = newtonsoft.json.nullvaluehandling.ignore;   ops.missingmemberhandling = newtonsoft.json.missingmemberhandling.ignore;   ops.defaultvaluehandling = newtonsoft.json.defaultvaluehandling.ignore;   ops.converters.add(new newtonsoft.json.converters.javascriptdatetimeconverter());    string strso = newtonsoft.json.jsonconvert.serializeobject(source,   bindent ? newtonsoft.json.formatting.indented : newtonsoft.json.formatting.none,   ops); 

i tried java code corresponding portion doesn't work.

from understanding, newtonsoft serializer takes object member variables , outputs json string represents object.

so can like:

product product = new product();  product.name = "apple"; product.expiry = new datetime(2008, 12, 28); product.price = 3.99m; product.sizes = new string[] { "small", "medium", "large" };  string output = jsonconvert.serializeobject(product); 

and you'll output string like:

{"name": "apple", "expiry": "\/date(1230375600000+1300)\/", "price": 3.99, "sizes": ["small", "medium", "large"] } 

now bad news blackberry library you're using doesn't use reflection examine structure of objects serialises. formatter rather serializer.

the news is pretty easy use. documentation here:

http://www.blackberry.com/developers/docs/6.0.0api/org/json/me/package-summary.html

in short, write object such 1 above, like:

 mystring = new jsonstringer()  .object()      .key("name")      .value("apple")      .key("expiry")      .value("date("+mydate.gettime()+")")  .endobject()  .tostring(); 

..and on. note constructing json structure element element, rather having json library assume object exact structure of data wish output.

hopefully give idea of how proceed.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -