我有这个json字符串,想要解码并使用它。但是在打印结果下面是空的。
$data = '{"Category":
06-30 16:23:52.198: I/s(23262): [{"class":"ir.aiga.apps.datastore.db.CategoryModel","id":1,"name":"علی"},{"class":"ir.aiga.apps.datastore.db.CategoryModel","id":2,"name":"گ"},{"class":"ir.aiga.apps.datastore.db.CategoryModel","id":3,"name":"علی"},{"class":"ir.aiga.apps.datastore.db.CategoryModel","id":4,"name":"ولی"},{"class":"ir.aiga.apps.datastore.db.CategoryModel","id":5,"name":"ن"},{"class":"ir.aiga.apps.datastore.db.CategoryModel","id":6,"name":"تتاا"},{"class":"ir.aiga.apps.datastore.db.CategoryModel","id":7,"name":"بی اسم"},{"class":"ir.aiga.apps.datastore.db.CategoryModel","id":8,"name":"تسلام"},{"class":"ir.aiga.apps.datastore.db.CategoryModel","id":9,"name":"میدانم"}]}';
print json_decode($data)->{'Category'};
我在java中使用下面的代码来生成json字符串
String s = "{\"Category\":\n";
List<CategoryModel> pmo = new ArrayList<CategoryModel>();
pmo = CategoryModule.getAllRecords(c);
s += new JSONSerializer().serialize(pmo);
s += "\n}";
有什么问题?
答案 0 :(得分:0)
试试这个:
$categories = json_decode($data)->{'Category'};
foreach($categories as $category){
echo $category-{'id'};
}