Omit questions if none present and fix parsing sites with no questions.
This commit is contained in:
parent
4a555748cd
commit
81358c16f9
@ -304,6 +304,7 @@ static bool mpw_marshal_write_json(
|
|||||||
if (strftime( dateString, sizeof( dateString ), "%FT%TZ", gmtime( &site->lastUsed ) ))
|
if (strftime( dateString, sizeof( dateString ), "%FT%TZ", gmtime( &site->lastUsed ) ))
|
||||||
json_object_object_add( json_site, "last_used", json_object_new_string( dateString ) );
|
json_object_object_add( json_site, "last_used", json_object_new_string( dateString ) );
|
||||||
|
|
||||||
|
if (site->questions_count) {
|
||||||
json_object *json_site_questions = json_object_new_object();
|
json_object *json_site_questions = json_object_new_object();
|
||||||
json_object_object_add( json_site, "questions", json_site_questions );
|
json_object_object_add( json_site, "questions", json_site_questions );
|
||||||
for (size_t q = 0; q < site->questions_count; ++q) {
|
for (size_t q = 0; q < site->questions_count; ++q) {
|
||||||
@ -327,6 +328,7 @@ static bool mpw_marshal_write_json(
|
|||||||
json_object_object_add( json_site_question, "answer", json_object_new_string( question->content ) );
|
json_object_object_add( json_site_question, "answer", json_object_new_string( question->content ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
json_object *json_site_mpw = json_object_new_object();
|
json_object *json_site_mpw = json_object_new_object();
|
||||||
json_object_object_add( json_site, "_ext_mpw", json_site_mpw );
|
json_object_object_add( json_site, "_ext_mpw", json_site_mpw );
|
||||||
@ -797,8 +799,9 @@ static MPMarshalledUser *mpw_marshal_read_json(
|
|||||||
site->loginContent = mpw_strdup( siteLoginName );
|
site->loginContent = mpw_strdup( siteLoginName );
|
||||||
}
|
}
|
||||||
|
|
||||||
json_object_iter json_site_question;
|
|
||||||
json_object *json_site_questions = mpw_get_json_section( json_site.val, "questions" );
|
json_object *json_site_questions = mpw_get_json_section( json_site.val, "questions" );
|
||||||
|
if (json_site_questions) {
|
||||||
|
json_object_iter json_site_question;
|
||||||
json_object_object_foreachC( json_site_questions, json_site_question ) {
|
json_object_object_foreachC( json_site_questions, json_site_question ) {
|
||||||
MPMarshalledQuestion *question = mpw_marshal_question( site, json_site_question.key );
|
MPMarshalledQuestion *question = mpw_marshal_question( site, json_site_question.key );
|
||||||
const char *answerContent = mpw_get_json_string( json_site_question.val, "answer", NULL );
|
const char *answerContent = mpw_get_json_string( json_site_question.val, "answer", NULL );
|
||||||
@ -817,6 +820,7 @@ static MPMarshalledUser *mpw_marshal_read_json(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
json_object_put( json_file );
|
json_object_put( json_file );
|
||||||
|
|
||||||
*error = (MPMarshalError){ .type = MPMarshalSuccess };
|
*error = (MPMarshalError){ .type = MPMarshalSuccess };
|
||||||
|
Loading…
Reference in New Issue
Block a user