This may be the most aggravating issue I've encountered in C3... (importing JSON file)

Not favoritedFavorited Favorited 0 favourites
  • 7 posts
From the Asset Store
[C2] [C3] Support C3 build service and Android 15+
  • Last year I wrote a C3 program that needed a big array. I put the data in Excel and wrote some VBA code to export it to JSON. Then I added the file to Construct 3.

    This works perfectly every time.

    Now I'm working on a new program and I want to replicate what I did before. I grabbed the Export code from my old program and put it in my new one, but I can't get it to import into C3. First, I validated the JSON file with json lint (it's perfect). Then I thought the issue was some Spanish characters I had in the text files. So as a test I replaced all the sentences with English, and made sure there were no trailing characters.

    It still won't import into Construct 3.

    Finally, I said 'screw it' and I just made a copy of the old program and replaced the old text with my new (English only) text.

    It STILL won't import into Construct 3.

    This makes NO sense to me. Does anyone have ANY idea what the problem could be???

    OLD JSON (imports perfectly)

    {"c2array": true,"size": [3,7,1],"data": [[[""],[""],[""],[""],[""],[""],[""]],[["7/23/2023"],["gapes"],["croon"],["blare"],["Do you remember mood rings? I have been wearing one since the 1980's, but I seem to have lost it."],["I'm not sure how to feel about that."],["0"]],[["7/24/2023"],["eek"],["reek"],["jut"],["Every weekend we take Mom to a restaurant called \"Aunt Alice's\". Their sign says: \"Breakfast! Any time!\""],["So I like to tell our waitress, Amanda: \"Pancakes, please… during the Renaissance.\""],["0"]]]}

    NEW JSON (won't import into C3)

    {"c2array": true,"size": [3,5,1],"data": [[["Spanish"],["English"],["Category"],["Bucket"],["Schedule"]],[["Hola"],["Hello"],["General Conversation"],["New"],["New"]],[["Hola"],["Hello"],["General Conversation"],["New"],["New"]]]}

    Again, these two files were generated using the EXACT SAME code, from a simple Excel sheet with x,y rows of text. (Both of the JSON files have this encoding: UTF-8-BOM.)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Well there’s nothing amiss with that json data as you typed it.

    I pasted them into a text file. Called it example.json, imported it into the files folder in the project, then used Ajax to load the file, loaded it into an array, then set some text from the asJson to see if it all worked. Which it did with my test with r458.2.

    + System: On start of layout
    -> AJAX: Request example.json (tag "")
    -> System: Wait for previous actions to complete
    -> Array: Load from JSON string AJAX.LastData
    -> TextInput: Set text to Array.AsJSON
  • Thanks, ROJOhound! I've got it working now.

    I attempted the same thing you did, I copied the BAD json data to a new text file and saved it. I then tried to replace the old file, but it STILL wouldn't import correctly to C3. (I was seeing the json data and not C3's table format.)

    Next, I tried deleting the old json file and I imported the new one as a NEW file. This time it worked! I even added some Spanish sentences to my Excel sheet, exported, and this time I did a Replace. It still worked!

    So my issue seems to be that I had a bad json file and replacing it with a good file didn't fix the problem. Can anyone explain how/why that could happen?

    UPDATE: Grok seems to think that the issue was caused because I tried to REPLACE a json file with width 32 and height 3, with a new json file having the dimensions width 32, height 6. Could this have been my problem???

  • Did you manually fiddle with the file at all? I don't know if this is relevant to your particular problem, but it's often not recommended to work with text files using something like Notepad, because sometimes it can insert and save some hidden/nonstandard characters such as line breaks and certain types of spaces that are undesirable. This doesn't have anything to do with Construct in particular (or again maybe not related to your problem at all). Notepad++ or VSC is usually better.

  • Good grief, this is driving me crazy. After getting the file to import correctly I noticed that I had TWO rows with category names. I'm not sure I need category names at all so I deleted one of the rows and I changed my Excel program to start at row 2 rather than row 1. (I was planning to just keep the category names in my Excel sheet only.)

    After I made this change I couldn't import the file again! I tried Replace initially, then I deleted the file and imported it as a New file. But unlike last time, it STILL wouldn't work. I was seeing just the json data and strangely, there were little squares around all the apostrophes in the text.

    Then I changed my code back to starting at row 1 again and now it imports just fine. WHY??? For what it's worth, in all cases my code has been outputting valid json files... they just won't import to C3.

    Did you manually fiddle with the file at all?

    Thanks for the reply, oosyrag! No, other than that one test, I just export the json file from Excel and then I try to import/replace the file in C3.

  • Just to be clear, what’s failing is the array load action fails to load your json since it’s wrong somehow?

    Have you looked at the browser console to see if the reason for not loading was logged?

    I hate guessing why something silently fails as much as the next guy. So assuming it’s the json generated from your excel file that’s not a proper array json you can make a checker to narrow it down.

  • Just to be clear, what’s failing is the array load action fails to load your json since it’s wrong somehow?

    Here's what I'm seeing:

    1. I have an Excel sheet with text in rows 1 through 7 (5 columns)

    2. I used VBA to export the text to json (C2/C3 format)

    3. I imported the json file into my project and it became a C3 "table"

    4. I modified my VBA code to only use rows 2 through 7 (row 1 is headers)

    5. I exported again, the json is valid, but when I imported the file into my C3 project it didn't turn into a table... I just saw the json data. (Plus, there were little squares around the apostrophes in the text).

    6. I changed the VBA code back to rows 1 through 7 and it imported into C3 perfectly again.

    If it breaks again I'll check the browser console and report back.

    Thanks again for the replies, ROJOhound. Really appreciate your help.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)