Posted By
|
Message
|
lembi2001
Registered 01/04/2005
Points 608
|
23rd November, 2011 at 11:42:47 -
This is a rather clear as mud post coming up but bear with me
I need to read some values from a text file and display certain parts of it in edit boxes.
The text file looks like this:
var _OLBookInfo = {"ISBN:9780440867579": {"publishers": [{"name": "Corgi"}], "identifiers": {"isbn_13": ["9780440867579"], "openlibrary": ["OL7523288M"], "isbn_10": ["0440867576"], "goodreads": ["462684"], "librarything": ["248136"]}, "title": "The Story of Tracy Beaker", "url": "http://openlibrary.org/books/OL7523288M/The_Story_of_Tracy_Beaker", "number_of_pages": 160, "cover": {"small": "http://covers.openlibrary.org/b/id/283402-S.jpg", "large": "http://covers.openlibrary.org/b/id/283402-L.jpg", "medium": "http://covers.openlibrary.org/b/id/283402-M.jpg"}, "subjects": [{"url": "http://openlibrary.org/subjects/fiction", "name": "Fiction"}, {"url": "http://openlibrary.org/subjects/foster_home_care", "name": "Foster home care"}, {"url": "http://openlibrary.org/subjects/mothers_and_daughters", "name": "Mothers and daughters"}, {"url": "http://openlibrary.org/subjects/overdrive", "name": "OverDrive"}, {"url": "http://openlibrary.org/subjects/juvenile_fiction", "name": "Juvenile Fiction"}], "publish_date": "November 28, 2006", "key": "/books/OL7523288M", "authors": [{"url": "http://openlibrary.org/authors/OL19365A/Jacqueline_Wilson", "name": "Jacqueline Wilson"}], "excerpts": [{"comment": "", "text": "My name is Tracy Beaker.", "first_sentence": true}]}};
What i need to retrieve is the book name, the author and the publisher. What i was doing initially was searching for key parts of it and then selecting the characters between certain points and displaying them. This works initially however the file structure is not standardised unfortunately so this fails badly.
What i want to know is if there is any way i can parse this information into a more readable format such as xml?
n/a
|
Fordom Nordanrikets konung
Registered 12/02/2009
Points 190
|
23rd November, 2011 at 15:20:01 -
Originally Posted by lembi2001This is a rather clear as mud post coming up but bear with me
I need to read some values from a text file and display certain parts of it in edit boxes.
The text file looks like this:
var _OLBookInfo = {"ISBN:9780440867579": {"publishers": [{"name": "Corgi"}], "identifiers": {"isbn_13": ["9780440867579"], "openlibrary": ["OL7523288M"], "isbn_10": ["0440867576"], "goodreads": ["462684"], "librarything": ["248136"]}, "title": "The Story of Tracy Beaker", "url": "http://openlibrary.org/books/OL7523288M/The_Story_of_Tracy_Beaker", "number_of_pages": 160, "cover": {"small": "http://covers.openlibrary.org/b/id/283402-S.jpg", "large": "http://covers.openlibrary.org/b/id/283402-L.jpg", "medium": "http://covers.openlibrary.org/b/id/283402-M.jpg"}, "subjects": [{"url": "http://openlibrary.org/subjects/fiction", "name": "Fiction"}, {"url": "http://openlibrary.org/subjects/foster_home_care", "name": "Foster home care"}, {"url": "http://openlibrary.org/subjects/mothers_and_daughters", "name": "Mothers and daughters"}, {"url": "http://openlibrary.org/subjects/overdrive", "name": "OverDrive"}, {"url": "http://openlibrary.org/subjects/juvenile_fiction", "name": "Juvenile Fiction"}], "publish_date": "November 28, 2006", "key": "/books/OL7523288M", "authors": [{"url": "http://openlibrary.org/authors/OL19365A/Jacqueline_Wilson", "name": "Jacqueline Wilson"}], "excerpts": [{"comment": "", "text": "My name is Tracy Beaker.", "first_sentence": true}]}};
What i need to retrieve is the book name, the author and the publisher. What i was doing initially was searching for key parts of it and then selecting the characters between certain points and displaying them. This works initially however the file structure is not standardised unfortunately so this fails badly.
What i want to know is if there is any way i can parse this information into a more readable format such as xml?
Something like:
GetSubstring("Text string with the character >"< ", 2)
GetSubstring("Text string with the character >"< ", 4)
You can use the string tokeizer ar any string manipulator.
The delimiter should be " ..
> or replace all the " with any other charactar when text has been loaded.
Note: This will not work unless the structure changes. You cans still get the substrings but not in order, by using forEach substring and looping through the string
Edited by Fordom
This forum is full of trolls and disinfo agents.
|
X_Sheep I had a custom rating before it was cool
Registered 01/03/2004
Points 1313
|
23rd November, 2011 at 19:41:42 -
Is there even a JSON extension for MMF2?
a/n
|
nivram
Registered 20/07/2006
Points 171
|
23rd November, 2011 at 21:56:16 -
There is not a JSON for MMF2
Marv
458 MMF2 & CTF 2.5 examples and games
http://www.castles-of-britain.com/mmf2examples.htm
|
lembi2001
Registered 01/04/2005
Points 608
|
24th November, 2011 at 09:18:33 -
Thanks for all the help everyone, i might have to look at an alternative way of doing this.
n/a
|
Fordom Nordanrikets konung
Registered 12/02/2009
Points 190
|
24th November, 2011 at 16:28:47 -
Originally Posted by lembi2001 Thanks for all the help everyone, i might have to look at an alternative way of doing this. I just gave you the working solution.
This forum is full of trolls and disinfo agents.
|
Sketchy Cornwall UK
Registered 06/11/2004
Points 1971
|
24th November, 2011 at 22:27:59 -
Originally Posted by Fordom
Originally Posted by lembi2001 Thanks for all the help everyone, i might have to look at an alternative way of doing this.
I just gave you the working solution.
Sort of... but it's much more complicated than that.
Publishers and Authors are both arrays, so they could contain multiple entries.
To get the publishers, you'd have to search for "publishers" - then get the next substring contained in square brackets - then search that for each instance of "name" - and then get the quoted text immediately following them.
Same for the authors.
n/a
|
lembi2001
Registered 01/04/2005
Points 608
|
25th November, 2011 at 10:44:49 -
As sketchy said, it isn't as clear cut as that unfortunately. I just had a working solution involving the list object however the resultant file structure is not standardised.
Sometimes there are spaces betweeen ,'s and "'s and sometimes there are not.
Fordom, if you could construct an example for me i could see if it would work with the files.
Thanks
EDIT: NVM - sorted it out now, the site i downloaded the files from offers them in an alternative format. After butchering the source url i managed to get it to download an rdf file which contains xml!!
Yippeee
Edited by lembi2001
n/a
|
|
|