B
B
beduin012015-11-25 16:45:04
JavaScript
beduin01, 2015-11-25 16:45:04

Why doesn't concat concatenate JSON correctly?

There are three JSON strings.
You need to fold them. I found the concat function in JS:
jsonArray1 = answers_string.concat(sub_answers);
As a result, not valid JSON is obtained. It's missing a comma between curly braces.
{"QID":3,"AID":2}{"SubAID":[]}
Question. Why and how to fix?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-11-25
@beduin01

Why

because you are concatenating strings.
jsonArray1 = JSON.stringify(
    [answers_string, sub_answers].map((str) => JSON.parse(str))
);

or
jsonArray1 = '[' + [answers_string, sub_answers].join(', ') + ']';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question