Jump to content

How to extract this (json?) string?


Popweb
Go to solution Solved by Popweb,

Recommended Posts

Hi there.

Does anyone here have an idea to how I can extract this to an array:

 

{s:4:"navn";s:18:"Some data";s:5:"alder";s:33:"Some data";s:5:"email";s:17:"Some data";s:5:"kirke";s:45:"Some data";s:17:"praktisk-baggrund";a:1:{i:0;s:71:"Some data";}s:17:"instrument-toggle";a:1:{i:0;s:2:"Ja";}s:10:"instrument";s:22:"Some data";s:10:"min-stemme";s:35:"Some data";s:9:"kommentar";s:106:"Some data";s:19:"vaerelses-fordeling";s:0:"";s:18:"vegetar-eller-lign";s:0:"";s:15:"FUK-laereplaner";a:1:{i:0;s:0:"";}}

 

It is a string picked up in a Wordpress database. Wordpress plugin.

 

I dont need all the s:#

 

I just need "navn": "Some data", "alder": "Some data", "email": "Some data". ("Some data" obviously varying).

 

$theArray['navn']="Some data";

$theArray['alder']="Some data";

and so forth

 

Can you help?

 

Thanks

John

Link to comment
Share on other sites

This is not JSON.

 

It looks like the serialization format of PHP, but then it's incomplete. The “a:<number of elements>:” in front of the outermost array is missing, so you can't just run this through unserialize().

 

Are you sure this is the exact string from the database? How does the plugin parse the string?

 

 

Link to comment
Share on other sites

Ah! Your're right!

 

I tried removing the first part - to try to make it look more json-like.

 

This is the full string:

a:12:{s:4:"navn";s:18:"Some data";s:5:"alder";s:33:"Some data";s:5:"email";s:17:"Some data";s:5:"kirke";s:45:"Some data";s:17:"praktisk-baggrund";a:1:{i:0;s:71:"Some data";}s:17:"instrument-toggle";a:1:{i:0;s:2:"Ja";}s:10:"instrument";s:22:"Some data";s:10:"min-stemme";s:35:"Some data";s:9:"kommentar";s:106:"Some data";s:19:"vaerelses-fordeling";s:0:"";s:18:"vegetar-eller-lign";s:0:"";s:15:"FUK-laereplaner";a:1:{i:0;s:0:"";}}

 

Aha... so it may be serialized?

 

I tried to unserialize(the string);

And got: Error at offset 49 of 600

 

Any ideas?

Link to comment
Share on other sites

I tried removing the first part - to try to make it look more json-like.

 

Not exactly the smartest idea, especially when you ask people to identify the data. ::)

 

 

 

This is the full string:

 

Not really. Obviously you've again changed the actual data and replaced it with your “Some data” dummy string.

 

We cannot help you when you only give us some fantasy data which is totally different from your actual data. How are we supposed to debug this? I understand that you may not want to hand out your real data, but then you'll have to fix it yourself.

Edited by Jacques1
Link to comment
Share on other sites

The string looks okay as serialized data. More likely than not you have a value that's not the same length as the s: part. I would double check your test data to make sure these match.

Ah! Your're right!

 

I tried removing the first part - to try to make it look more json-like.

 

This is the full string:

a:12:{s:4:"navn";s:18:"Some data";s:5:"alder";s:33:"Some data";s:5:"email";s:17:"Some data";s:5:"kirke";s:45:"Some data";s:17:"praktisk-baggrund";a:1:{i:0;s:71:"Some data";}s:17:"instrument-toggle";a:1:{i:0;s:2:"Ja";}s:10:"instrument";s:22:"Some data";s:10:"min-stemme";s:35:"Some data";s:9:"kommentar";s:106:"Some data";s:19:"vaerelses-fordeling";s:0:"";s:18:"vegetar-eller-lign";s:0:"";s:15:"FUK-laereplaner";a:1:{i:0;s:0:"";}}

 

Aha... so it may be serialized?

 

I tried to unserialize(the string);

And got: Error at offset 49 of 600

 

Any ideas?

Link to comment
Share on other sites

And Jaques... well...that was sort of rude?! ...

 

Obviously I didn't intend to not show the entire string?! I removed the first part to test. And forgot to paste it back in, when asking for help. Dont tell me you never make mistakes?

Yes I replaced the data with "Some data". But not to hide anything. That was to make the string more readable. Another mistake. I am sorry about that.

 

Here is one of the actual strings: (Except: I changed the users email adress. but I counted the new number of chars and changed the value.)

 

a:12:{s:4:"navn";s:18:"Margit Anna Brodam";s:5:"alder";s:33:"13 år når sommerskolen afholdes";s:5:"email";s:19:"adresse@adresse.com";s:5:"kirke";s:45:"Asminderød Kirke / personligt meldlem af FUK";s:17:"praktisk-baggrund";a:1:{i:0;s:71:"Jeg kender alle nodeværdier og tonenavne og kan klappe noterede rytmer";}s:17:"instrument-toggle";a:1:{i:0;s:2:"Ja";}s:10:"instrument";s:22:"Violin begynder niveau";s:10:"min-stemme";s:35:"Dyb 2. sopran med smuk stor klang ";s:9:"kommentar";s:106:"Cille Buch er Margits korlærer. Margit har sunget i kirkekor i 5½ år og tillige i koncertkoret i 2 år.";s:19:"vaerelses-fordeling";s:0:"";s:18:"vegetar-eller-lign";s:0:"";s:15:"FUK-laereplaner";a:1:{i:0;s:0:"";}}

 

I counted the size of the different vars and checked the s-numbers. Turns out that every time a danish letter (æ, ø and å) appears in the string, the number differs from the actual number of chars.

I suppose that might be it? The number is too big, when there are danish chars in the vars.

 

Any suggestions?

 

Thank you all for taking the time to read, and try to help out.
Even if you are being rude. ;-)
I need the help, and I dont have to pay for it - so ofcourse I have to deal with whatever response I get. :-)

Thx

John

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.