Monday, 29 September 2014

iOS Grab Random Entry From XML File



I am working on displaying a random Bible verse from a KJV XML file that I have, but am having some issues with the formatting of the XML, as it essentially has numerous arrays within it. It has a format like this:



<?xml version="1.0"?>
<bible translation="King James Version">
<testament name="Old">
<book name="Genesis">
<chapter number="1">
<verse number="1">
</verse>
</chapter>
</book>
</testament>
</bible>


I have tried getting this converted to a plist file to handle it better, but am running into issues on that front as well. I used an online program to convert this to JSON file, but when using plutil from terminal to convert to a plist file, I get the following error:



Unexpected character { at line 1 / JSON error: No string key for value in object around character 1.


The JSON format looks like this for the first few lines:



{
"bible": {
"-translation": "King James Version",
"testament": [
{
"-name": "Old",
"book": [
{
"-name": "Genesis",
"chapter": [
{
"-number": "1",
"verse": [
{
"-number": "1",
"#text": "In the beginning God created the heaven and the earth."
},


I would appreciate any suggestions, either on converting this to a plist file, or to making it work with XML.


No comments:

Post a Comment