首页 > 编程知识 正文

java解析json数组,java.lang.assertionerror

时间:2023-05-05 01:26:47 阅读:109898 作者:2042

询问mldy/pgettingdeprecatedmessageforjsonparserforspringbootapp,

jonobjectjsonobject=newjsonparser (.parse (result ).getAsJsonObject );

What is the alternative?

Based on the javadoc for Gson 2.8.6

No need to instantiate this class,use the static methods instead。

andfollowingarethealternativestobeused。

//jsonString is of type java.lang .无形糖精/pjsonobjectjsonobject=JSON parser.parse string (JSON string ).getasjsonon

//readerisoftypejava.io.yjdjj/pjsonobjectjsonobject=JSON parser.parsereader (reader ).getAsJsonObject;

//jsonreaderisoftypecom.Google.gson.stream.jsonyjdjj/pjsonobjectjsonobject=JSON parser.parsereader (

Example

importstaticorg.JUnit.assert.assert true;

import com.Google.gson.JSON object;

import com.Google.gson.JSON parser;

公共类测试{

publicstaticvoidmain (字符串的拼命口红args ) )。

stringjsonstring=' {' name' :'高贵的电脑} ';

jsonobjectjsonobjectalt=JSON parser.parse string (JSON string ).getAsJsonObject );

//showsdeprecatedwarningfornewjsonparser () and parse (JSON string ) )。

jsonobjectjsonobject=newjsonparser (.parse ) JSONstring ).getAsJsonObject;

assert true (jsonobjectalt.equals ) JSONobject );

}

资料来源: https://stack overflow.com/questions/60771386/JSON parser-is-deprecated

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。