开发者

JSON Object in Java

how do I convert a string url = "http://abcdef.com/" to JSONObject having a field "url" ="http://abcdef.com/" ? The result I am g开发者_开发百科etting is : "url" = "http:\/\/abcdef.com".So, I am not able to get around '/'


If that's the way your JSONObject serializes strings (which is legal as per the JSON spec), there's no way to get around it directly unless you alter the behavior of the JSONObject. (by rewriting, subclassing, or wrapping -- see below.)

Indirectly, if you have an opportunity to intercept the JSONObject output, convert to string, and replace all instances of \/ with /.

update: I'm not familiar with the specific implementation you're using, but if you have existing code that expects a JSONObject and takes an interface rather than a particular class implementation, you could write a decorator or wrapper class that holds an instance to the "real" JSONObject class, and delegates everything to the JSONObject, but fixes up the conversion of strings so it converts \/ to / after-the-fact automatically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜