我有一个像这样的字符串:
{
"OperationResult": [
{
"CA::Read:PackageItems": {
"Read.PackageItem.RemoteBalanceAssigned": false,
"Read.PackageItem.CLSpvInfo": "1|-1#-9223372036854775000",
"PackageList":
[
"TopSim-4GSim1GBData",
"TopSim-ATBReactivation"
],
"PackageTypeList":
[
"optional-unsubscribed", "optional-unsubscribed"
],
"PackageFunctionalNameList":
[
"FreeUnits",
"AccumulationReward+MultipleThresholds"
],
"PackageSubStateList":
[
"",
""
],
"PackageEligibilityList":
[
true,
true
]
}
}]
}
我正在尝试将其放入数组。但我想过滤此字符串,只放入PackageList":["xxxx-yyy","zzz-zzz"]
和“ PackageSubStateList":[TRUE,FALSE]}
介于两者之间的任何东西都应过滤掉。
结果数组应类似于:
PackageList {
name: xxxx-yyy,
state: TRUE,
}
....
答案 0 :(得分:-1)
//The json posted in the question is invalid, assuming valid json gets used here afterwards:
$string = '{"OperationResult":[{"CA::Read:PackageItems":{"PackageList":["xxxx-yyy","zzz-zzz"],
"PackageTypeList":["optional-unsubscribed","optional-"optional-unsubscribed""],
"PackageFunctionalNameList":["FreeUnits","AccumulationReward+MultipleThresholds"],
"PackageSubStateList":[TRUE,FALSE]}';
$object = json_decode($string);
$wanted = $object['OperationResult']['CA::Read:PackageItems'];
$wanted
现在应该包含您需要的内容