json - 我要用java解析一段字符串,该怎么做?
怪我咯
怪我咯 2017-04-17 11:31:22
0
5
537

字符串比如是这样

“{"info":{"funds":{"free":{"btc":"1.042309","cny":"510.021","ltc":"0.01468"},"freezed":{"btc":"0","cny":"7490.319","ltc":"0"}}},"result":true}
”

是不是要把这个字符串先变成json?我最终要解析出里面BTC多少LTC多少等

具体代码如何写,求指教。

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(5)
小葫芦

It’s nothing more than nesting json one by one. Just follow the json format from simple to complex and figure it out one by one.

Reuse the third-party jar package for analysis. .
The ones I often use include gson, fastjson, etc. It is recommended to use fastjson. I feel that the efficiency is good.

PHPzhong

https://github.com/alibaba/fastjson

wiki : https://github.com/Alibaba/fastjson/wiki/%E9%A6%96%E9%A1%B5

大家讲道理

You can also use the gson package provided by Google, or Alibaba's fastjson. You can write a bean based on what you want to parse, and then use the above package to parse it

PHPzhong

Look at this http://json.org/
The class libraries available for java are:

org.json.
org.json.me.
Jackson JSON Processor.
Json-lib.
JSON Tools.
Stringtree.
SOJO.
Jettison.
json-taglib.
XStream.
Flexjson.
JON tools.
Argo.
jsonij.
fastjson.
mjson.
jjson.
json-simple.
json-io.
JsonMarshaller.
google-gson.
Json-smart.
FOSS Nova JSON.
Corn CONVERTER.

刘奇

The native code may look like this;

String jsonString = '{"info":{"funds":{"free":{"btc":"1.042309","cny":"510.021","ltc":"0.01468"},"freezed":{"btc":"0","cny":"7490.319","ltc":"0"}}},"result":true}';  //当然咯不能使用单引号“'”

JSONObject json = new JSONObject(jsonString);
JSONObject info= json.getJSONObject("info");
JSONObject funds = info.getJSONObect("funds");
JSONObject free = funds.getJSONObject("free");
int btc = funds.getInt("btc");

Hmm, it’s so annoying! ! !

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template