Page 1 of 1

Text fille help

Posted: Thu Apr 23, 2020 6:20 pm
by Jeff Barnes
I have a text file created by another program (it's a json file)
I need to find a way to allow a user to delete an entry from the text file via a user interface.

Can anyone point me in the right direction. The issue I'm having is how to locate the specific entry and remove it.

Here is what the file looks like:

Code: Select all


{
    "items": [
        {
            "name": "color 1",
            "image": "",
            "day": "1",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "1",
            "location": "",
            "description": ""
        },
        {
            "name": "color 2",
            "image": "",
            "day": "2",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "2",
            "location": "",
            "description": ""
        },
        {
            "name": "color 3",
            "image": "",
            "day": "3",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "3",
            "location": "",
            "description": ""
        },
        {
            "name": "color 4",
            "image": "",
            "day": "4",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "4",
            "location": "",
            "description": ""
        },
        {
            "name": "color 5",
            "image": "",
            "day": "5",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "5",
            "location": "",
            "description": ""
        },
        {
            "name": "color 6",
            "image": "",
            "day": "6",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "6",
            "location": "",
            "description": ""
        },
        {
            "name": "color 7",
            "image": "",
            "day": "7",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "7",
            "location": "",
            "description": ""
        },
        {
            "name": "color 8",
            "image": "",
            "day": "8",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "8",
            "location": "",
            "description": ""
        },
        {
            "name": "color 9",
            "image": "",
            "day": "9",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "9",
            "location": "",
            "description": ""
        },
        {
            "name": "color 10",
            "image": "",
            "day": "10",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "10",
            "location": "",
            "description": ""
        },

        {
            "name": "xxxRobertoRoberto Tapia",
            "image": "events/images/roberto_tapia.jpg",
            "day": "8",
            "month": "3",
            "year": "2020",
            "time": "8:00 pm",
            "duration": "4",
            "color": "4",
            "location": "",
            "description": ""
        } 
    ]


 

Re: Text fille help

Posted: Thu Apr 23, 2020 6:33 pm
by cnavarro
Look

Image

Code: Select all

//----------------------------------------------------------------------------//
//
//----------------------------------------------------------------------------//

#include "Fivewin.ch"

//----------------------------------------------------------------------------//

Function Main()

   local cText
   local hHash  := { => }
   TEXT INTO cText
{
    "items": [
        {
            "name": "color 1",
            "image": "",
            "day": "1",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "1",
            "location": "",
            "description": ""
        },
        {
            "name": "color 2",
            "image": "",
            "day": "2",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "2",
            "location": "",
            "description": ""
        },
        {
            "name": "color 3",
            "image": "",
            "day": "3",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "3",
            "location": "",
            "description": ""
        },
        {
            "name": "color 4",
            "image": "",
            "day": "4",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "4",
            "location": "",
            "description": ""
        },
        {
            "name": "color 5",
            "image": "",
            "day": "5",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "5",
            "location": "",
            "description": ""
        },
        {
            "name": "color 6",
            "image": "",
            "day": "6",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "6",
            "location": "",
            "description": ""
        },
        {
            "name": "color 7",
            "image": "",
            "day": "7",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "7",
            "location": "",
            "description": ""
        },
        {
            "name": "color 8",
            "image": "",
            "day": "8",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "8",
            "location": "",
            "description": ""
        },
        {
            "name": "color 9",
            "image": "",
            "day": "9",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "9",
            "location": "",
            "description": ""
        },
        {
            "name": "color 10",
            "image": "",
            "day": "10",
            "month": "4",
            "year": "2020",
            "time": "",
            "duration": "1",
            "color": "10",
            "location": "",
            "description": ""
        },

        {
            "name": "xxxRobertoRoberto Tapia",
            "image": "events/images/roberto_tapia.jpg",
            "day": "8",
            "month": "3",
            "year": "2020",
            "time": "8:00 pm",
            "duration": "4",
            "color": "4",
            "location": "",
            "description": ""
        }
    ]
}
   ENDTEXT

   hb_JsonDecode( cText, @hHash )
   XBrowse( hHash[ "items" ] )
   
Return nil

//----------------------------------------------------------------------------//

 

Re: Text fille help

Posted: Mon Apr 27, 2020 11:34 am
by Jeff Barnes
Excellent. Thanks :)

Re: Text fille help

Posted: Mon Apr 27, 2020 4:33 pm
by Jeff Barnes
How would I add a new entry ?

Re: Text fille help

Posted: Mon Apr 27, 2020 5:04 pm
by nageswaragunupudi
Click on the + button

Re: Text fille help

Posted: Mon Apr 27, 2020 5:10 pm
by Jeff Barnes
Sorry, I should have provided more info....
(never worked with json or hash before so please forgive any dumb questions)

I am reading a json file into a text var (cText) and working with the data in the background.
I'm not displaying the data in a browse.