0

I am having a problem parsing the following xAPI string into an array. The issue is that both parse_str() and parse_url() parse the URL within the quotes contained in the [content] ... which kills the JSON format.

Authorization=Basic YmV0b1234XZlddle9ighrXRvc3VhdmVwY999929yZA==&Content-Type=application/json&X-Experience-API-Version=1.0.0&statementId=ef0ca1d6-1234-4e02-b403-7d4aab0df62c&content={"verb":{"id":"http://adlnet.gov/expapi/verbs/experienced"},"object":{"id":"http://mytest.myfavsite.com/?post_type=gb_xapi_content&p=52&preview=true/6lgIX5Hxep0","definition":{"name":{"und":"SpecificStatement"},"description":{"und":"SpecificStatement"},"type":"http://adlnet.gov/expapi/activities/module"},"objectType":"Activity"},"context":{"contextActivities":{"grouping":{"id":"http://mytest.myfavsite.com/?post_type=gb_xapi_content&p=52&preview=true"},"parent":{"id":"http://mytest.myfavsite.com/?post_type=gb_xapi_content&p=52&preview=true"}},"registration":"36fc1ee0-2849-1234-b697-71cd4cad1b6e"},"version":"1.0.0","actor":{"mbox":"mailto:betosuave@home.tld","name":"beto","objectType":"Agent"}}

What I would like to wind-up with is an array of element with an intact JSON string in the [content] array element.

Is there a method of parsing the string like parse_str() does ... while ignoring anything inside the quotes of the JSON element - e.g., {"id":"http://mytest.myfavsite.com/?post_type=gb_xapi_content&p=52&preview=true"}

Thank you in-advance for any ideas.

Beto
  • 151
  • 2
  • 8
  • 1
    instead of getting it thru a url, do you have another way of getting that data? like `POST` instead? – Kevin Feb 03 '16 at 00:42
  • @Beto Please note that the string you provide is not a URL. Are you sure it is correct? Then, if is possible, follow the Ghost idea. I have not found nothing best of my previous answer. – fusion3k Feb 03 '16 at 01:19

2 Answers2

0

Try to json_decode($string) first and then run parse_str() on selected element.

Michal Przybylowicz
  • 1,558
  • 3
  • 16
  • 22
0

The question is interesting.

While will search for a clean solution, you can certainly try in the rude, old-fashioned way:

json_decode( substr( $str, strpos( $yourString, '&content=' )+9 ) )

This works fine!

fusion3k
  • 11,568
  • 4
  • 25
  • 47