我在React App中使用以下方法将Object
转换为字符串。一切正常,但是我想在屏幕上输出结果,而在输出的周围没有""
。
renderConfigInfoCellRow = configInfoKey => {
const { lconfigInfo } = this.props;
return (
<tr key={configInfoKey}>
<td className="pt-3 text-muted font-weight-bold w-25">{configInfoKey}</td>
{(typeof lconfigInfo.sql[configInfoKey] === 'string' && (
<td className="pt-3">{JSON.stringify(lconfigInfo.sql[configInfoKey])}</td>
)}
</tr>
);
};
我在这里使用它:
<tbody>
{Object.keys(lconfigInfo.sql).map(configInfoKey =>
this.renderConfigInfoCellRow(configInfoKey)
)}
</tbody>
关于如何删除""
周围的"output"
的任何想法?或者,如果它们是JSON.Stringify的替代方法。谢谢!!
答案 0 :(得分:2)
使用JSON.stringify()没有意义,如果数据不是对象,请尝试更改
此JSON.stringify(lconfigInfo.sql[configInfoKey])
到lconfigInfo.sql[configInfoKey]
。
还有一种情况,您需要检查lconfigInfo.sql[configInfoKey]
是否为字符串,然后尝试再次将其转换为字符串。
答案 1 :(得分:2)
JSON.stringify
输出有效的JSON,因此,如果将其传递给字符串,它将返回一个用""
包装的字符串。
您正在检查lconfigInfo.sql[configInfoKey]
的值是否为字符串,因此可以直接将其打印出来,如:
<td className="pt-3">{lconfigInfo.sql[configInfoKey]}</td>
答案 2 :(得分:1)
尝试select cast(event_date AS date) AS date,
sum( status = 'Yes' ) as Positive,
sum( status <> 'Yes' ) as Negative
from events e
group by cast(event_date AS date);
:
String userName= "Someone";
String isRanked= " is ranked at position ";
String rank= "1";
String withScore = " with score of ";
String score = "154";
String in = " in ";
String featureName = "Cooking";
String finalString= serName+isRanked+rank+withScore+score+in+featureName;
final SpannableStringBuilder sb = new SpannableStringBuilder(finalString);
// Span to set text color to some RGB value
final ForegroundColorSpan fcs = new ForegroundColorSpan(context.getResources().getColor(R.color.bright_blue));
// Span to make text bold
final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD);
// Set the text color for first 4 characters
int endAt = 0;
endAt = splited[0].length();
sb.setSpan(fcs, 0, endAt, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
// make them also bold
sb.setSpan(fcs,userName.length()+isRanked.length(),userName.length()+isRanked.length()+rank.length(),Spannable.SPAN_INCLUSIVE_INCLUSIVE);
sb.setSpan(bss, 0, endAt, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
infoStmt.setText(sb);