当我使用var_dump()函数检查数组的值时。
var_dump($data['content']);
我有结果
array(1) { [0]=> array(10) { ["IDUser"]=> string(1) "1" ["Name"]=> string(5) "admin" ["Password"]=> string(32) "44ca5fa5c67e434b9e779c5febc46f06" ["Fullname"]=> string(18) "Nguyễn Tá Lợi" ["Gender"]=> string(1) "0" ["Birthday"]=> string(10) "0000-00-00" ["Address"]=> string(0) "" ["Email"]=> string(0) "" ["PhoneNumber"]=> string(0) "" ["Status"]=> string(1) "1" } }
我希望通过键["名称"]获取价值,因此我使用$data['content']['Name']
但它不正确
如何获得"名称"的价值在这个数组?
答案 0 :(得分:3)
$data['content'][0]['Name']
应该这样做
答案 1 :(得分:2)
public void Load() throws FileNotFoundException {
Type typeOfHashMap = new TypeToken<LinkedHashMap<String, Object>>(){}.getType();
FileReader reader = new FileReader(file);
HashMap<String, Object> loadedMap = mainGson.fromJson(reader,typeOfHashMap);
for(Field f: this.getClass().getDeclaredFields()) {
if (!f.isAnnotationPresent(Store.class)) {
continue;
}
try {
f.setAccessible(true);
Store annotation = f.getAnnotation(Store.class);
Object defaultValue = DefaultRegistrator.getDefault(this.getClass(),f);
if (!loadedMap.containsKey(annotation.valueName())) {
f.set(this, defaultValue);
continue;
}
Object loadedValue = mainGson.fromJson(
loadedMap.get(annotation.valueName()).toString(), f.getType()
);
f.set(this, loadedValue);
} catch(IllegalAccessException e) {
}
}
}
的值在Name
的 0 索引上可用,因此您无法获取名称值:
content
您需要将姓名命名为:
$data['content']['Name']