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

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

如何以 Json 格式顯示包含員工和多個(gè)地址的地圖

如何以 Json 格式顯示包含員工和多個(gè)地址的地圖

胡子哥哥 2021-08-25 09:53:44
我創(chuàng)建了兩個(gè)類 Employee 和 Address 并且對(duì)于每個(gè)員工都會(huì)有多個(gè)地址。我想以 JSON 格式顯示這些地址。我在下面嘗試了一些代碼。您能告訴我如何更改代碼以按以下格式顯示地圖值嗎?同樣,我想顯示 ID 為 2 的員工。{ id: 1 name: John Addresses: [  {   addrLine1:StreetABC Line 1   addrLine2: StreetABC Line 2   city:CityABC   zip: ZipABC  },  {   addrLine1:StreetXYZ Line 1   addrLine2: StreetXYZ Line 2   city:CityXYZ   zip: ZipXYZ  } ]}這是Test.class;import java.util.*;import com.fasterxml.jackson.core.type.TypeReference;import com.fasterxml.jackson.databind.ObjectMapper;import org.json.JSONObject;public class Test {    public static void main(String args[]) {        ObjectMapper mapper = new ObjectMapper();        Employee e1= new Employee(1,"John");        Employee e2= new Employee(2,"Robert");        Address a1 = new Address ("StreetABC Line 1","StreetABC Line 2", "CityABC","ZipABC");        Address a2 = new Address ("StreetXYZ Line 1","StreetXYZ Line 2", "CityXYZ","ZipXYZ");        Address a3 = new Address ("StreetLMN Line 1","StreetLMN Line 2", "CityLMN","ZipLMN");        Address a4 = new Address ("StreetJQK Line 1","StreetJQK Line 2", "CityJQK","ZipJQK");        List<Address> address1=new ArrayList<Address>();        List<Address> address2=new ArrayList<Address>();        List<Employee> employees = new ArrayList<Employee>();        employees.add(e1);        employees.add(e2);        address1.add(a1);        address1.add(a2);        address2.add(a3);        address2.add(a4);        Map<Employee, List<Address>> employeeAddressmap=new HashMap<Employee, List<Address>>();        employeeAddressmap.put(e1,address1);        employeeAddressmap.put(e2,address2);        try {            mapper.writeValueAsString(employeeAddressmap);        } catch (Exception e) {            e.printStackTrace();        }    }}Employee.class 喜歡 ;class Employee{    private int id;    private String name;    public Employee(int id, String name) {        this.id = id;        this.name = name;    }    public void setId(int id){        this.id=id;    }
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 157 瀏覽
慕課專欄
更多

添加回答

舉報(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)