私は、このドメインクラスを持っている:Grails。ドメインクラス。 JSON文字列の問題
package test
class Credit {
String office;
String branch;
String name;
Integer code;
Integer number;
Integer term;
Integer amount;
Integer rate;
static hasMany = [ debts : Debt,
fronts : Front,
securities : Security,
lawyers : Lawyer,
guarantes : Guarante]
static constraints = {
}
}
私はこれらのフィールドに関する情報のみを含む文字列JSONを作成する必要があります。
String office;
String branch;
String name;
Integer code;
Integer number;
Integer term;
Integer amount;
Integer rate;
私が試してみてください。
rezult = Credit.list(fetch:[debts:"lazy", fronts: 'lazy', securities: "lazy", lawyers:"lazy", quarantes:"lazy"])
render new JSON(success: true, message: 'ok', data:rezult);
しかしJSON文字列には私はすべてのデータを持っています:(債務、前払い、有価証券...文字列内でも。 しかし、私はこのデータは必要ありません。
どのように使用しないでください。
ANSWER:あなたはこの問題を解決するために、JSONビルダを使用する必要があるとしている
render(contentType:"text/json") {
success=true
message='ok'
totalCount=Credit.count()
data = array {
for(d in results) {
data office:d.office,
branch:d.branch,
name: d.name,
code:d.code,
number:d.number,
term:d.term,
amount:d.amount,
rate:d.rate
}
}
}