Nested content types mostly supported.
"Mostly" in this context means that I'm not confident all field offsets and types are fully supported from the USF JSON, but it should be good enoug hto generate output.
This commit is contained in:
parent
31c9d313d1
commit
965c1009e4
1 changed files with 53 additions and 51 deletions
|
|
@ -3,7 +3,6 @@ package bible
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
|
@ -44,13 +43,15 @@ type ChapterDecl struct {
|
|||
}
|
||||
|
||||
type Content struct {
|
||||
Text string
|
||||
Type string `json:"type"`
|
||||
Number int `json:"number"`
|
||||
NoteId int `json:"noteId"`
|
||||
LineBreak bool `json:"lineBreak"`
|
||||
Poem int `json:"poem"`
|
||||
Content []Content
|
||||
Text string
|
||||
Number int
|
||||
NoteID int `json:"-"`
|
||||
PoemOffset int
|
||||
IsHeading bool
|
||||
IsLineBreak bool
|
||||
IsNote bool
|
||||
IsVerse bool
|
||||
Content []Content `json:"-"`
|
||||
}
|
||||
|
||||
func (c *Content) UnmarshalJSON(d []byte) error {
|
||||
|
|
@ -59,69 +60,70 @@ func (c *Content) UnmarshalJSON(d []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var peek []json.RawMessage
|
||||
if err := json.Unmarshal(d, &peek); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, p := range peek {
|
||||
fmt.Printf("%v\n", p)
|
||||
}
|
||||
|
||||
/*if d[0] == '"' {
|
||||
json.Unmarshal(d, &c.Text)
|
||||
}
|
||||
|
||||
if d[0] == '{' {
|
||||
switch d[0] {
|
||||
case '{':
|
||||
var peek map[string]json.RawMessage
|
||||
if err := json.Unmarshal(d, &peek); err != nil {
|
||||
return err
|
||||
}
|
||||
if t, ok := peek["type"]; ok {
|
||||
var s string
|
||||
if err := json.Unmarshal(t, &s); err != nil {
|
||||
if v, ok := peek["type"]; ok {
|
||||
var tp string
|
||||
if err := json.Unmarshal(v, &tp); err != nil {
|
||||
return err
|
||||
}
|
||||
switch s {
|
||||
switch tp {
|
||||
case "heading":
|
||||
if ct, ok := peek["content"]; ok {
|
||||
content := make([]Content, 0)
|
||||
c.IsHeading = true
|
||||
if err := json.Unmarshal(ct, &content); err != nil {
|
||||
return err
|
||||
} else {
|
||||
c.Content = content
|
||||
}
|
||||
}
|
||||
c.IsHeading = true
|
||||
case "line_break":
|
||||
c.IsLineBreak = true
|
||||
case "verse":
|
||||
if nb, ok := peek["number"]; ok {
|
||||
if err := json.Unmarshal(nb, &c.Number); err != nil {
|
||||
c.IsVerse = true
|
||||
if n, ok := peek["number"]; ok {
|
||||
if err := json.Unmarshal(n, &c.Number); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if ct, ok := peek["content"]; ok {
|
||||
content := make([]Content, 0)
|
||||
c.IsVerse = true
|
||||
if err := json.Unmarshal(ct, &content); err != nil {
|
||||
return err
|
||||
} else {
|
||||
c.Content = content
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if _, ok := peek["line_break"]; ok {
|
||||
c.IsLineBreak = true
|
||||
if v, ok := peek["content"]; ok {
|
||||
var rawContent []json.RawMessage
|
||||
if err := json.Unmarshal(v, &rawContent); err != nil {
|
||||
return err
|
||||
} else {
|
||||
for _, rc := range rawContent {
|
||||
var sc Content
|
||||
if err := json.Unmarshal(rc, &sc); err != nil {
|
||||
return err
|
||||
}
|
||||
c.Content = append(c.Content, sc)
|
||||
}
|
||||
}
|
||||
}
|
||||
if nd, ok := peek["noteId"]; ok {
|
||||
c.IsNote = true
|
||||
json.Unmarshal(nd, &c.NoteId)
|
||||
if v, ok := peek["lineBreak"]; ok {
|
||||
if err := json.Unmarshal(v, &c.IsLineBreak); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
if v, ok := peek["nodeId"]; ok {
|
||||
if err := json.Unmarshal(v, &c.NoteID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if v, ok := peek["poem"]; ok {
|
||||
if err := json.Unmarshal(v, &c.PoemOffset); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if v, ok := peek["text"]; ok {
|
||||
if err := json.Unmarshal(v, &c.Text); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
case '"':
|
||||
if err := json.Unmarshal(d, &c.Text); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue