-1

I have a string like:

     {
        "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
                          ]
            }
        }]
    }

I am trying to get it into array. but I want filter this string and only put PackageList":["xxxx-yyy","zzz-zzz"] and "PackageSubStateList":[TRUE,FALSE]}

Any thing in between should be filter out.

The resulted array should be like:

PackageList {
               name: xxxx-yyy,
               state: TRUE,
             }
               ....
Fshamri
  • 1,346
  • 4
  • 17
  • 32
  • 1
    Why not just parse it and access the object props? – BenM Aug 07 '18 at 10:03
  • that erm `string` looks like an object? – treyBake Aug 07 '18 at 10:03
  • 3
    Possible duplicate of [How do I extract data from JSON with PHP?](https://stackoverflow.com/questions/29308898/how-do-i-extract-data-from-json-with-php) – Andreas Aug 07 '18 at 10:04
  • 1
    Is that an exact copy of the string? The `"optional-"optional-unsubscribed""` looks wrong and makes it pretty much un-parsable. – jeroen Aug 07 '18 at 10:06
  • my web service returns response in raw test format. I couldn't parse it using simple xml – Fshamri Aug 07 '18 at 10:07
  • 1
    If you have tried using simple xml to parse it, that should have been included in the question along with the code you tried. – Andreas Aug 07 '18 at 10:09
  • 1
    @Fshamri In this case, you should rethink about using this service or call their support and ask for help. If response is not in the form of XML, JSON etc, then parsing will be difficult and won't make sense. – nice_dev Aug 07 '18 at 10:11
  • If this is your string, I saw some problem : 1/ `"optional-"optional-unsubscribed""` looks wrong for me, 2/ For me it missed `}]}` at the end to close the `{"OperationResult":[{` at the beginning – Mickaël Leger Aug 07 '18 at 10:13

1 Answers1

-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 should now contain what you need

Marvin Fischer
  • 2,552
  • 3
  • 23
  • 34