简体   繁体   English

如何使用 Z6716608096280862A88268CDDB0DEZ 访问以 NULL 开头的 JSON object?

[英]How do I access a JSON object that begins with NULL using gson?

I am trying to access a web API by using gson to parse through it into a string.我正在尝试通过使用 gson 将其解析为字符串来访问 web API。 The URL returns: URL 返回:

NULL { "status": "yes", "problem": "400072500002031600000009007000150400000396010090000003003015002065000000000703000", "result": "489672531752831649316549827238157496547396218691284753873415962165928374924763185", "time": "0.0472550392151" }

The above json element starts with NULL, is what is causing a problem for me to access its objects.上面的 json 元素以 NULL 开头,这导致我无法访问其对象。 I want to get the numbers in "result" object as a string.我想将“结果”中的数字 object 作为字符串。 Using Gson only to parse the JSON objects please.请仅使用 Gson 解析 JSON 对象。 Any help would be appreciated!任何帮助,将不胜感激!

This (with NULL) is not a valid JSON.这(带 NULL)不是有效的 JSON。 Use any online validator to prove, if you need it.如果需要,请使用任何在线验证器来证明。

If it happens constantly try to contact API provider or just remove this null in the beginning, before parsing.如果经常发生这种情况,请尝试联系 API 提供商,或者在解析之前从开头删除此 null。

EDIT:编辑:

If you can process original answer before passing to Gson deserializer you can probably do:如果您可以在传递给 Gson 解串器之前处理原始答案,您可能可以这样做:

String originalJson = "NULL { \"status\": \"yes\", \"problem\": "
+ "\"400072500002031600000009007000150400000396010090000003003015002065000000000703000\", "
+ "\"result\": \"489672531752831649316549827238157496547396218691284753873415962165928374924763185\", "
 + "\"time\": \"0.0472550392151\" }";
        
String json = originalJson.startsWith("NULL ") ? originalJson.replaceFirst("NULL ", "") : originalJson;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM