Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with setFieldValue when Trying to Save Element #150

Open
zadro opened this issue Feb 24, 2024 · 0 comments
Open

Error with setFieldValue when Trying to Save Element #150

zadro opened this issue Feb 24, 2024 · 0 comments

Comments

@zadro
Copy link

zadro commented Feb 24, 2024

Trying to set a field in a plugin, using the following:

$entry->setFieldValue('json', Json::encode($variable));

JSON value is a string and in this format:

{
    "Some Title": {
        "question": "What is Foo?",
        "answer": "hello\r\n\r\nthis \r\n\r\nis a multi-line!"
    },
    "Another Title": {
        "question": "What is bar?",
        "answer": "This is another answer to the question."
    }
}

Error is below when trying to store an already formatted JSON string using:

"name": "Exception",
    "message": "json_decode(): Argument #1 ($json) must be of type string, array given",
    "code": 0,
    "error": "json_decode(): Argument #1 ($json) must be of type string, array given",
    "exception": "TypeError",
    "file": "/home/zadro/www/clientname/vendor/chasegiunta/craft-jason/src/fields/JasonField.php",
    "line": 127

https://github.com/chasegiunta/craft-jason/issues/108

I can confirm the fix @stevecomrie proposes #108 is a working solution.

However, the fix is required on both lines 127 and 425 in JasonField.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant