解析json对象包含多个数组

{
  "JobSalarys":[
    {
      "Salary":"10000-15000",
      "Location_L":"北京",
      "Location_P":"21.93%",
      "Education_L":"本科及以上",
      "Education_P":"66.31%",
      "Experience_L":"3年以上",
      "Experience_P":"33.69%",
      "SalaryPro":0.2
    },
    {
      "Salary":"20000-30000",
      "Location_L":"北京",
      "Location_P":"41.95%",
      "Education_L":"本科及以上",
      "Education_P":"81.69%",
      "Experience_L":"3年以上",
      "Experience_P":"44.51%",
      "SalaryPro":0.19
    },
    {
      "Salary":"3000-7000",
      "Location_L":"成都",
      "Location_P":"9.50%",
      "Education_L":"大专及以上",
      "Education_P":"70.25%",
      "Experience_L":"经验不限",
      "Experience_P":"81.90%",
      "SalaryPro":0.19
    },
    {
      "Salary":"15000-20000",
      "Location_L":"北京",
      "Location_P":"26.73%",
      "Education_L":"本科及以上",
      "Education_P":"75.39%",
      "Experience_L":"3年以上",
      "Experience_P":"43.14%",
      "SalaryPro":0.15
    },
    {
      "Salary":"7000-10000",
      "Location_L":"北京",
      "Location_P":"22.88%",
      "Education_L":"大专及以上",
      "Education_P":"48.28%",
      "Experience_L":"经验不限",
      "Experience_P":"54.55%",
      "SalaryPro":0.13
    },
    {
      "Salary":"30000-100000",
      "Location_L":"北京",
      "Location_P":"40.87%",
      "Education_L":"本科及以上",
      "Education_P":"82.65%",
      "Experience_L":"5年以上",
      "Experience_P":"36.07%",
      "SalaryPro":0.09
    }
  ]
}


解析方法:
public class MainActivity extends AppCompatActivity {
    private TextView tv;
    private Button bt;
//    private String readyJson = "[{\"a\":\"123\",\"b\":\"456\",\"F\":{\"aa\":\"111\",\"bb\":\"222\"}},{\"a\":\"321\",\"b\":\"654\",\"F\":{\"aa\":\"333\",\"bb\":\"444\"}}]";
    //工资范围
    private List salary_range = new ArrayList<>();
    //工资占比
    private List salary_size = new ArrayList<>();
    //地点
    private List addr = new ArrayList<>();
    //地点占比
    private List addr_size = new ArrayList<>();
    //经验
    private List exp = new ArrayList<>();
    //经验占比
    private List exp_size = new ArrayList<>();
    //学历
    private List edu = new ArrayList<>();
    //学历占比
    private List edu_size = new ArrayList<>();
    private String readyJson = "{\n" +
            "    \"JobSalarys\": [\n" +
            "        {\n" +
            "            \"Salary\": \"10000-15000\",\n" +
            "            \"Location_L\": \"北京\",\n" +
            "            \"Location_P\": \"21.93%\",\n" +
            "            \"Education_L\": \"本科及以上\",\n" +
            "            \"Education_P\": \"66.31%\",\n" +
            "            \"Experience_L\": \"3年以上\",\n" +
            "            \"Experience_P\": \"33.69%\",\n" +
            "            \"SalaryPro\": 0.2\n" +
            "        },\n" +
            "        {\n" +
            "            \"Salary\": \"20000-30000\",\n" +
            "            \"Location_L\": \"北京\",\n" +
            "            \"Location_P\": \"41.95%\",\n" +
            "            \"Education_L\": \"本科及以上\",\n" +
            "            \"Education_P\": \"81.69%\",\n" +
            "            \"Experience_L\": \"3年以上\",\n" +
            "            \"Experience_P\": \"44.51%\",\n" +
            "            \"SalaryPro\": 0.19\n" +
            "        },\n" +
            "        {\n" +
            "            \"Salary\": \"3000-7000\",\n" +
            "            \"Location_L\": \"成都\",\n" +
            "            \"Location_P\": \"9.50%\",\n" +
            "            \"Education_L\": \"大专及以上\",\n" +
            "            \"Education_P\": \"70.25%\",\n" +
            "            \"Experience_L\": \"经验不限\",\n" +
            "            \"Experience_P\": \"81.90%\",\n" +
            "            \"SalaryPro\": 0.19\n" +
            "        },\n" +
            "        {\n" +
            "            \"Salary\": \"15000-20000\",\n" +
            "            \"Location_L\": \"北京\",\n" +
            "            \"Location_P\": \"26.73%\",\n" +
            "            \"Education_L\": \"本科及以上\",\n" +
            "            \"Education_P\": \"75.39%\",\n" +
            "            \"Experience_L\": \"3年以上\",\n" +
            "            \"Experience_P\": \"43.14%\",\n" +
            "            \"SalaryPro\": 0.15\n" +
            "        },\n" +
            "        {\n" +
            "            \"Salary\": \"7000-10000\",\n" +
            "            \"Location_L\": \"北京\",\n" +
            "            \"Location_P\": \"22.88%\",\n" +
            "            \"Education_L\": \"大专及以上\",\n" +
            "            \"Education_P\": \"48.28%\",\n" +
            "            \"Experience_L\": \"经验不限\",\n" +
            "            \"Experience_P\": \"54.55%\",\n" +
            "            \"SalaryPro\": 0.13\n" +
            "        },\n" +
            "        {\n" +
            "            \"Salary\": \"30000-100000\",\n" +
            "            \"Location_L\": \"北京\",\n" +
            "            \"Location_P\": \"40.87%\",\n" +
            "            \"Education_L\": \"本科及以上\",\n" +
            "            \"Education_P\": \"82.65%\",\n" +
            "            \"Experience_L\": \"5年以上\",\n" +
            "            \"Experience_P\": \"36.07%\",\n" +
            "            \"SalaryPro\": 0.09\n" +
            "        }\n" +
            "    ]}";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv = findViewById(R.id.tv);
        bt = findViewById(R.id.start);
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                parseJsonWithJSONObject(readyJson);
            }
        });
    }

    private void parseJsonWithJSONObject(String readyJson) {
        try {
//            JSONArray jsonArray = new JSONArray(readyJson);
//            for (int i = 0; i

你可能感兴趣的:(android)