第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

無(wú)法反序列化java.util.ArrayList的實(shí)例

無(wú)法反序列化java.util.ArrayList的實(shí)例

PHP
森林海 2021-05-13 10:19:59
我在嘗試從JSON文件獲取數(shù)據(jù)時(shí)遇到了麻煩。我的JAVA端正在工作,但是在組裝JSON的PHP中進(jìn)行了更改,因?yàn)槲覠o(wú)法執(zhí)行解析器,因此我不知道在PHP中知道我正在獲取的JSON格式,但是我可以訪問(wèn)代碼。JSON掛載的頁(yè)面是這樣的:<?php    $startTime = microtime(true);    include_once("../utils/config.php");    include_once("../utils/utils.php");    include_once("../services/rest.utils.php");    header("Content-Type: application/json",true);    $from = getADate('from', true);    $to = getADate('to', false);    $fromDate = '';    $toDate = '';    if ($from <> '') { $fromDate = $from; }    if ($to <> 'NULL') { $toDate = $to; }    $body = file_get_contents('php://input');    if (signatureCheck($body)) {        $cta = 0;        $database = conectaDatabase();        $script = '';        $pfx = Config::getPrefixo();        $sql = "SELECT RelatorioID, ProfessorID, AlunoID, TurmaID,                Bimestre, Data, TipoRelatorio, Conteudo, Situacao FROM {$pfx}Relatorios                WHERE Data >= $fromDate";        if ($toDate <> '') {             $sql .= " AND Data < $toDate";        }           $qry = $database->query($sql);        $lista = array();        $cta = 0;        while ($row = $qry->fetchObject()) {            $row->TipoRelatorio = utf8_encode($row->TipoRelatorio);            $row->Conteudo = utf8_encode($row->Conteudo);            $lista[] = $row;            $cta++;        }        @$output->response = new StdClass(); // Anonymous object, remove the warning        $output->response->descricao = "$cta relatórios importados";        $output->response->status = 200;        $output->relatorios = $lista;        $endTime = microtime(true);        $timeSpent = $endTime - $startTime;        $output->response->timeSpent = $timeSpent;        $saida = json_encode($output, JSON_UNESCAPED_UNICODE);        echo $saida;        desconectaDB($database);    }
查看完整描述

1 回答

?
HUWWW

TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊

問(wèn)題是您的JSON如下所示:


{

  "response": {

    ...

  },

  "relatorios": [

    {

      ...

    }

  ]

}

您正在嘗試將其直接映射到relatorios列表。您應(yīng)該RestResponse改為創(chuàng)建另一個(gè)對(duì)象。這應(yīng)該包含整個(gè)JSON響應(yīng)內(nèi)容:


public class RestResponse {

    private MyResponse response;

    private List<RelatorioResponse> relatorios;

    // getter and setter

}

該response對(duì)象應(yīng)代表responseJSON中的部分。如果不需要,也可以添加@JsonIgnoreProperties(ignoreUnknown = true)到RestResponse類中并忽略response屬性:


@JsonIgnoreProperties(ignoreUnknown = true)

public static class RestResponse {

    private List<RelatorioResponse> relatorios;

    // getter and setter

}

您的請(qǐng)求代碼應(yīng)如下所示:


HttpEntity<String> entity = new HttpEntity<>("parameters", new HttpHeaders());

ResponseEntity<RestResponse> response = new RestTemplate().exchange(targetUrl, HttpMethod.GET, entity, RestResponse.class);

List<RelatorioResponse> responses = response.getBody().getRelatorios();


查看完整回答
反對(duì) 回復(fù) 2021-05-28
  • 1 回答
  • 0 關(guān)注
  • 348 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)