文档说如果没有这样的成员,JsonObject#get方法返回null.那不准确; 有时JsonNull返回一个对象而不是null.
检查GSON中是否存在特定字段的惯用法是什么?我希望避免这种笨重的风格:
jsonElement = jsonObject.get("optional_field");
if (jsonElement != null && !jsonElement.isJsonNull()) {
s = jsonElement .getAsString();
}
Run Code Online (Sandbox Code Playgroud)
为什么GSON使用JsonNull而不是null?
有一个答案是什么null和之间的差异JsonNull.在我上面的问题中,我正在寻找原因.
我正在学习如何使用Spin.js,以便在加载网页时显示加载指示符(微调器).
我得到了它的工作,但我不确定我是否在正确的页面生命周期中调用旋转/停止.以前可以显示微调器$(window).ready吗?
<script type="text/javascript">
var spinner;
$(window).ready(function loadingAnimation() {
var opts = {
lines: 13, // The number of lines to draw
length: 7, // The length of each line
width: 4, // The line thickness
radius: 10, // The radius of the inner circle
corners: 1, // Corner roundness (0..1)
rotate: 0, // The rotation offset
color: '#000', // #rgb or #rrggbb
speed: 1, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false, …Run Code Online (Sandbox Code Playgroud)