Home Forums Weaver Xtreme Theme Issue with json parsing posts from Weaver Xtreme with Plus

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #69792
    arctexas
    Participant

    I am building an Android app that needs to be able to display the posts in my site,  I use Weaver Xtreme 4.4.8 Options – Plus ( 4.0).  When I pull down the posts located at https://arctx.org/wp-json/wp/v2/posts”, my logcat shows that the app is finding things correctly, because I get this, “Response from url: [{“id”:113,”date”:”2021-11-23T18:31:20″,”date_gmt”:”2021-11-23T18:31:20″,”guid”:{“rendered”:”https:\/\/arctx.org\/?p=113″},”…(much more included, just left off here. I left the actual link above so if you wanted you could see what it actually returns.

    Upon doing some research, there seems to be an issue with the “rendered” portion, I was wondering if there is a way to strip out the extraneous characters?  I realize that this is a Weaver forum, I am just hoping that someone has some ideas, I’ve done multiple google searches over the past week and so far nothing has shown up.

    thank you

    #69793
    scrambler
    Moderator

    May be @weaver can comment…

    #69794
    Weaver
    Keymaster

    That link now returns not found messages, so I assume you’re continuing work.

    I know very little about using phone apps to show WP posts. Not exactly sure of what your goal is. Are you somehow rendering JSON versions of pages? Don’t even know how one would do that from WP.

    I’ve only very recently done anything with phone apps, and I’m using Flutter/Dart which is a completely amazing package that allows development of apps that essentially work identically as Android, iOS, MacOS, Windows, and web pages. But my app does not touch the web at all, so I really can’t offer much insight to what you are attempting.

    #69795
    arctexas
    Participant

    I just noticed the link in the question was incorrect, I’m getting the right data from it.  Yes, I’m trying to incorporate a list of posts from my site into one of my android apps.  Right now I’m pulling down this info. “2021-12-09 12:18:51.153 15973-16021/com.arctexas E/ArcGetPosts: Response from url: [{“id”:113,”title”:{“rendered”:”New England\u2019s Small, Diverse Farms are a Boon for Shrubland Birds”}},{“id”:110,”title”:{“rendered”:”Cattle raisers oppose changes to Federal water regulation”}},{“id”:108,”title”:{“rendered”:”FCA board approves bookletter on governance of wholesale funding and related practices”}},{“id”:106,”title”:{“rendered”:”Texas cattle raisers fight to protect water rights in Texas Supreme Court briefing”}},{“id”:103,”title”:{“rendered”:”Episode 11 \u2013 Parlez-vous fran\u00e7ais?”}},{“id”:101,”title”:{“rendered”:”Episode 10 \u2013 Did Spanish Colonization have a chance?”}},{“id”:96,”title”:{“rendered”:”Episode 9 – The French make a try in Texas”}},{“id”:93,”title”:{“rendered”:”Episode 8- The Spanish Presidios and tensions begin rising between cultures”}},{“id”:90,”title”:{“rendered”:”Episode 7- The Spanish Missions”}},{“id”:87,”title”:{“rendered”:”Episode 6 \u2013 A clash of cultures between the Spanish and the local peoples”}}]”

    I’ll keep putzing with it, trying to get away from using the Android Webview by using the WordPress API…it’s a challenge….

    #69796
    Weaver
    Keymaster

    That looks like a typical JSON definiton with nested components.  I’m pretty sure that the Android Library, either Java or Kotlin would have library methods available to convert the JSON to a Map. I don’t know the meaning of “rendered”, but it does look like a key to a map.

    It looks as if there are post titles there, but don’t see any content. Maybe you need different parameter values for your JSON request?

    I have never needed to dig into any WP APIs to get post content in JSON format.

    After a second look, it does seem that your returned JSON is returning Post IDs, a Post Title field that has actual title string included as a “rendered” element. Looks like nested Maps. You should NOT think about stripping anything, but converting the JSON to an appropriate structure (I’m guessing a Map). Then you can extract the title. There’s probably an ability to fetch the post body in the JSON data as well.

    #69797
    arctexas
    Participant

    The data is

    title {1}
    rendered: (title of post verbiage)
    excerpt {2}
    rendered: (the excerpt verbiage)
    content {3}
    rendered: (the actual post)

    While I am testing I am just trying to get the id and title to come across and then get parsed correctly, I figure that once I conquer that, I can bring down the excerpt and content. I’ve now read numerous reference pages, both on google developer and wordpress developer that give me the terminology and some tutorials that I have tried to implement and that’s what been giving me the fits.  Most of the articles I can find are dated from 2011-2018 and (as you know) things change quickly in this world we work in, so what worked 10 years ago, not so much now.
    I’m going to look into the mapping issue on Monday, I’ve got to get away from the keyboard for awhile.  If you know of any good books or tutorials I’d appreciate the info.
    Thanks a bunch

     

     

    #69804
    Weaver
    Keymaster

    As I said, the excerpt you showed looks like standard JSON.

    JSON is a standard for representing data in text form. I’ve used it in the process of converting a CSV spreadsheet to JSON, which I then convert to a Map. So it would seem that WP is providing JSON generated from a WP post.

    I don’t know what language you are using to program your app, but it most likely would be Java or Kotlin.

    If you haven’t used the Map data type, you should spend time understandig  that. There WILL be built in support for converting that JASON directly to Maps. There should be no need for you to figure out how to parse that JSON. Just get the JSON, convert it to a Map, then you have full and easy (once you’ve mastered Maps) access to the data to use however you want to draw it on the screen.

    I do not know if the HTML has bee stripped from the JSON, but I really don’t know what is avaiable for displaying HTML via a phone App.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.