Skip to content

Adding Array Data to Array Field Failing #93

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

Closed
aminediab opened this issue Mar 5, 2019 · 22 comments
Closed

Adding Array Data to Array Field Failing #93

aminediab opened this issue Mar 5, 2019 · 22 comments

Comments

@aminediab
Copy link

aminediab commented Mar 5, 2019

Hi Phill,
I have modified the diet plan class and added an ingredients array field, and successfully created the object. now when testing the add function I got an parse error on response with Unexpected token s in JSON at position 43, check the code below:

void addArray() async {
var list = ["sugar", "rice", "salt"];
var apiResponse = await DietPlan().getObject('j2S0JZhbpC');
if (apiResponse.success && apiResponse.result != null) {
var dietPlan = (apiResponse.result as DietPlan);
var response = await dietPlan.add('ingredients', list);
dietPlan.save();
} else {
print('ERROR');
}
}

@phillwiggins
Copy link
Member

phillwiggins commented Mar 5, 2019 via email

@aminediab
Copy link
Author

The server access log showing:

185.40.210.13 - - [2019-03-05T13:17:23.696Z] "POST /serverInfo" 200 2 ms 218 bytes_in 731 bytes_out
185.40.210.13 - - [2019-03-05T13:17:17.448Z] "PUT /classes/Diet_Plans/j2S0JZhbpC" 200 7 ms 164 bytes_in 40 bytes_out
185.40.210.13 - - [2019-03-05T13:17:17.012Z] "PUT /classes/Diet_Plans" 400 2 ms 61 bytes_in 53 bytes_out
185.40.210.13 - - [2019-03-05T13:17:16.153Z] "GET /classes/Diet_Plans/j2S0JZhbpC" 200 7 ms 0 bytes_in 242 bytes_out
185.40.210.13 - - [2019-03-05T13:17:14.930Z] "GET /health" 200 1 ms 0 bytes_in 15 bytes_out
185.40.210.13 - - [2019-03-05T13:16:46.959Z] "PUT /classes/Diet_Plans/j2S0JZhbpC" 200 28 ms 164 bytes_in 40 bytes_out
185.40.210.13 - - [2019-03-05T13:16:46.510Z] "PUT /classes/Diet_Plans" 400 2 ms 61 bytes_in 53 bytes_out
185.40.210.13 - - [2019-03-05T13:16:45.443Z] "GET /classes/Diet_Plans/j2S0JZhbpC" 200 7 ms 0 bytes_in 242 bytes_out
185.40.210.13 - - [2019-03-05T13:16:44.002Z] "GET /health" 200 3 ms 0 bytes_in 15 bytes_out
185.40.210.13 - - [2019-03-05T13:13:53.281Z] "PUT /classes/Diet_Plans/j2S0JZhbpC" 200 26 ms 164 bytes_in 40 bytes_out
185.40.210.13 - - [2019-03-05T13:13:52.778Z] "PUT /classes/Diet_Plans" 400 19 ms 61 bytes_in 53 bytes_out
185.40.210.13 - - [2019-03-05T13:13:51.564Z] "GET /classes/Diet_Plans/j2S0JZhbpC" 200 28 ms 0 bytes_in 242 bytes_out
185.40.210.13 - - [2019-03-05T13:13:50.431Z] "GET /health" 200 3 ms 0 bytes_in 15 bytes_out

@aminediab
Copy link
Author

the debug console output:

Launching lib\main.dart on T06 in debug mode...
Built build\app\outputs\apk\debug\app-debug.apk.
D/libc-netbsd(31415): [getaddrinfo]: hostname=parseapi.back4app.com; servname=(null); netid=0; mark=0
D/libc-netbsd(31415): [getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=1024; ai_family=0
D/libc-netbsd(31415): getaddrinfo: parseapi.back4app.com get result from proxy gai_error = 0
I/SurfaceView(31415): updateWindow -- OnPreDrawListener, mHaveFrame = true, this = io.flutter.view.FlutterView{6c63f0a VFE...... .F....I. 0,0-720,1184}
I/SurfaceView(31415): updateWindow -- OnPreDrawListener, mHaveFrame = true, this = io.flutter.view.FlutterView{6c63f0a VFE...... .F....I. 0,0-720,1184}
I/SurfaceView(31415): updateWindow -- OnPreDrawListener, mHaveFrame = true, this = io.flutter.view.FlutterView{6c63f0a VFE...... .F....I. 0,0-720,1184}
I/SurfaceView(31415): updateWindow -- OnPreDrawListener, mHaveFrame = true, this = io.flutter.view.FlutterView{6c63f0a VFE...... .F....I. 0,0-720,1184}
I/SurfaceView(31415): updateWindow -- OnPreDrawListener, mHaveFrame = true, this = io.flutter.view.FlutterView{6c63f0a VFE...... .F....I. 0,0-720,1184}
I/SurfaceView(31415): updateWindow -- OnPreDrawListener, mHaveFrame = true, this = io.flutter.view.FlutterView{6c63f0a VFE...... .F....I. 0,0-720,1184}
I/SurfaceView(31415): updateWindow -- OnPreDrawListener, mHaveFrame = true, this = io.flutter.view.FlutterView{6c63f0a VFE...... .F....I. 0,0-720,1184}
I/SurfaceView(31415): updateWindow -- OnPreDrawListener, mHaveFrame = true, this = io.flutter.view.FlutterView{6c63f0a VFE...... .F....I. 0,0-720,1184}
I/SurfaceView(31415): updateWindow -- OnPreDrawListener, mHaveFrame = true, this = io.flutter.view.FlutterView{6c63f0a VFE...... .F....I. 0,0-720,1184}
I/SurfaceView(31415): updateWindow -- OnPreDrawListener, mHaveFrame = true, this = io.flutter.view.FlutterView{6c63f0a VFE...... .F....I. 0,0-720,1184}
I/SurfaceView(31415): updateWindow -- OnPreDrawListener, mHaveFrame = true, this = io.flutter.view.FlutterView{6c63f0a VFE...... .F....I. 0,0-720,1184}
I/flutter (31415):
I/flutter (31415): ----
I/flutter (31415): API Response (ParseMain : ParseApiRQ.healthCheck) :
I/flutter (31415): Status Code: 200
I/flutter (31415): Payload: {status: ok}
I/flutter (31415): ----
D/libc-netbsd(31415): [getaddrinfo]: hostname=parseapi.back4app.com; servname=(null); netid=0; mark=0
D/libc-netbsd(31415): [getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=1024; ai_family=0
D/libc-netbsd(31415): getaddrinfo: parseapi.back4app.com get result from proxy gai_error = 0
D/libc-netbsd(31415): [getaddrinfo]: hostname=parseapi.back4app.com; servname=(null); netid=0; mark=0
D/libc-netbsd(31415): [getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=1024; ai_family=0
D/libc-netbsd(31415): getaddrinfo: parseapi.back4app.com get result from proxy gai_error = 0
I/flutter (31415): Unexpected token s in JSON at position 43

@aminediab
Copy link
Author

Is this what you want?

@phillwiggins
Copy link
Member

phillwiggins commented Mar 5, 2019 via email

@aminediab
Copy link
Author

Phill, I think it is apparently trying to parse something that isn't Json, that's my take on it!

@phillwiggins
Copy link
Member

Hey, I think this might have been fixed by one of our contributors. Can you try again please?

@RodrigoSMarques
Copy link
Contributor

Hi @phillwiggins. I did the fix and it's tested.

@aminediab, The correct way to implement is:

void addArray() async {
var list = ["sugar", "rice", "salt"];
var apiResponse = await DietPlan().getObject('j2S0JZhbpC');
if (apiResponse.success && apiResponse.result != null) {
var dietPlan = (apiResponse.result as DietPlan);
var response = await dietPlan.add('ingredients', list);
//dietPlan.save();
} else {
print('ERROR');
}
}

@aminediab
Copy link
Author

Hi Phill & Rodrigo,

The ERROR persists. The first portion; the apiResponse is a success and it returns the object correctly, however adding fails with a Parse Error, (Unexpected token s in JSON at position 43)
can you confirm how you have tested it?

thanks,

@aminediab
Copy link
Author

Just to be clear, the add operation should append the list to the array field, i have manually entered a string list in the ingredients field and then ran the code as suggested!

@RodrigoSMarques
Copy link
Contributor

@phillwiggins
Do not you have to release a new release with the changes?
I noticed that they are only in Branch: Master.

Do you know if it is possible to use the master instead of a release?

@phillwiggins
Copy link
Member

Maybe try this?

parse_server_sdk:
git: git://github.com/phillwiggins/flutter_parse_sdk.git

@RodrigoSMarques
Copy link
Contributor

RodrigoSMarques commented Mar 8, 2019

@aminediab
update pubspec.yaml to :


dependencies:
flutter:
sdk: flutter
#parse_server_sdk: ^1.0.15
parse_server_sdk:
git: git://github.com/phillwiggins/flutter_parse_sdk.git


Try again.


Sample yy code:
_apiResponse = await objeto.add("lista", ["a", "b", "c"]);
if (apiResponse.success) {
print(apiResponse.result.toString());
} else {
print(apiResponse.error.toString());
}

apiResponse = await objeto.addUnique("lista", ["a", "a","d"]);
if (apiResponse.success) {
print(apiResponse.result.toString());
} else {
print(apiResponse.error.toString());
}

apiResponse = await objeto.addUnique("lista", ["a", "d", "e"]);
if (apiResponse.success) {
print(apiResponse.result.toString());
} else {
print(apiResponse.error.toString());
}
apiResponse = await objeto.addUnique("lista", ["f"]);
if (apiResponse.success) {
print(apiResponse.result.toString());
} else {
print(apiResponse.error.toString());
}

apiResponse = await objeto.remove("lista", ["d","e"]);
if (apiResponse.success) {
print(apiResponse.result.toString());
} else {
print(apiResponse.error.toString());
}_


My log:
flutter: {lista: [a, b, a, b, c], updatedAt: 2019-03-08T18:04:05.788Z}
flutter: {lista: [a, b, a, b, c, d], updatedAt: 2019-03-08T18:04:05.931Z}
flutter: {lista: [a, b, a, b, c, d, e], updatedAt: 2019-03-08T18:04:06.075Z}
flutter: {lista: [a, b, a, b, c, d, e, f], updatedAt: 2019-03-08T18:04:06.217Z}
flutter: {lista: [a, b, a, b, c, f], updatedAt: 2019-03-08T18:04:06.359Z}

@RodrigoSMarques
Copy link
Contributor

Maybe try this?

parse_server_sdk:
git: git://github.com/phillwiggins/flutter_parse_sdk.git

Thanks @phillwiggins . It worked

@aminediab
Copy link
Author

Hi All,
It is working!!! thank you for all your efforts, Phill and Rodrigo.
cheers,

@phillwiggins
Copy link
Member

phillwiggins commented Mar 8, 2019 via email

@RodrigoSMarques
Copy link
Contributor

@phillwiggins
this issue can be closed.

Resolved in the last release.

Updated documentation.

@RodrigoSMarques
Copy link
Contributor

@phillwiggins
Close this issue to keep open only what is in trouble.
Resolved in previous releases. It is inactive because it has not received any new comments.

@MungaraJay
Copy link

MungaraJay commented Jul 24, 2020

Let say, if i use the following method to add array. It's working.

var manage = ParseObject('Test')
..set('name', "Test")
..set('email', "[email protected]")
..set('age', 15)
..setAdd('hobby', ['Play Chess', 'Watch Movies']);
await manage.save();

This saves my values in the Back4App database. But, when i try following code to update my class values,

var manage = ParseObject('Test')
..objectId = widget.id
..set('name', "Test")
..set("email", "[email protected]")
..set('age', 18)
..setAdd('hobby', ['Travel', 'Fight']);
await manage.update();

Above code doesn't update my current object/list anyway. How to update parse objects and parse list for back4App ?

Thanks.
But, it's not updating my object

@phillwiggins
Copy link
Member

phillwiggins commented Jul 24, 2020 via email

@MungaraJay
Copy link

MungaraJay commented Jul 24, 2020

@phillwiggins

I have tried updating the same reference as well. like,

ParseObject('Employee')
..objectId = widget.id
..set('name', nameController.text.trim())
..set("email", emailController.text.trim())
..set('age', ageController.text.trim())
..setAdd('hobby', ['Travel', 'Fight'])
..update();

But, it doesn't work.

So, Can you please add that line of code here?

@phillwiggins
Copy link
Member

var manage = ParseObject('Test')
..set('name', "Test")
..set('email', "[email protected]")
..set('age', 15)
..setAdd('hobby', ['Play Chess', 'Watch Movies']);
await manage.save();

manage
..setAdd('hobby', ['Travel', 'Fight'])
await manage.update();

Something like that should work?

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

4 participants