我正在编写一个java程序,通过http get方法获取json数据,并在导航对象树后返回以下内容:

{
"year":"2015",
"period":"M03",
"periodName":"March",
"value":"141178",
"footnotes":[{}]
}

现在我想把它转化成一个浮点数,我试着这样做:
JSONParser parser = new JSONParser();

try
{
    JSONObject
    BLSemployment = ( JSONObject ) parser.parse( _RDATA );
    BLSemployment =       ( ( JSONObject ) BLSemployment.get( "Results" ) );

    JSONArray
    BLSemploymentseries = ( ( JSONArray ) BLSemployment.get( "series" ) );

    BLSemployment =       ( ( JSONObject ) BLSemploymentseries.get( 0 ) );
    BLSemploymentseries = ( ( JSONArray ) BLSemployment.get( "data" ) );

    for( int i = 0; i < 12; i++ )
    {
        BLSemployment = ( (JSONObject) BLSemploymentseries.get( i ) );

        HistoricalNonFarmPayrollData[i] = Float.parseFloat( JSONValue.toJSONString( BLSemployment.get( "value" ) ).replace( "\"" , "" ) );
        HistoricalNonFarmPayrollYear[i] = JSONValue.toJSONString( BLSemployment.get( "year" ) );
        HistoricalNonFarmPayrollMonth[i] = JSONValue.toJSONString( BLSemployment.get( "periodName" ) );
    }
}
catch ( ParseException pe )
{
    System.out.println( pe );
}

但是现在我得到了错误:
Exception in thread "main" java.lang.NullPointerException
        at BLSFramework.getNonFarmPayrolls(playground.java:354)
        at playground.main(playground.java:27)

最佳答案

解决方案:偶尔BLS网站不发送数据的一段时间内,我是编码在这段时间。

10-05 17:52
查看更多