fastjson 转 对象套对象[转]

阅读更多

转:https://blog.csdn.net/ywj776199845/article/details/84351499

String httpResult = "******"; 

Result toResult = JSON.parseObject(httpResult, new TypeReference>() {});

 

 

package A;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
 
import pojo.Child;
import pojo.Preant;
 
public class A {
 
	public static void main(String[] args) {
		String str = "{\"name\":\"jack\",\"age\":\"20\",\"ch\":{\"name\":\"sum\",\"age\":\"10\"}}";
		Preant p =JSON.parseObject(str, new TypeReference() {});
		System.out.println(p.getName());
		Child ch =p.getCh();
		System.out.println(ch.getAge());
	}
	
}

@Data
public class Preant {
 
	String name;
	int age;
	Child ch;
}


@Data
public class Child {
	String name;
	int age;
	
}


 

 

你可能感兴趣的:(fastjson 转 对象套对象[转])