开发者

Problem parse integer within JSON response

开发者 https://www.devze.com 2023-04-04 18:32 出处:网络
How to convert number values in json string to string format. such as 100 - \"100\" i am getting the result from response and set to a string (in java).

How to convert number values in json string to string format. such as

100 - "100"

i am getting the result from response and set to a string (in java).

anybody suggest the right way

my whole st开发者_运维技巧ring is

{name:"MyNode", width:200, height:100, my:[1,2,"ambika"]}

i need the result should be

{name:"MyNode", width:"200", height:"100", my:["1","2","ambika"]}


You can do 100 - parseInt("100") or 100 - +"100".


I think you are looking for something that want to load in into an JSON-like object. However, the above is not a valid JSON object but fortunately a YAML object, which is a superset of a JSON object.

You can use YAML library for Java to load your string into YAML object, and use it just like JSON object in your implementation.

JYaml

Yaml temp = new Yaml();
temp.load({name:"MyNode", width:200, height:100, my:[1,2,"ambika"]});

You can then use temp to extract the value using keys,etc. Just looking for the JavaDocs they provided

0

精彩评论

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