0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【UiPath】String.Formatと中括弧のエスケープ

0
Posted at

先日、以下のようなJSON形式の文字列を作りたいという場面があった。

{"id" : "ABC"}

"ABC"の部分は可変なので、{0}に置き換えてString.Formatで当て込む……としようとしたところ、実行エラーに。

image.png

image.png

Input string was not in a correct format. 文字列が正しい形式ではないと言われているようだ。
変数xには文字列" {""id"" : ""{0}""} "を代入している。ダブルクォーテーションのエスケープに問題があるのかと思ったが、 " { {0} } "まで削っても同じエラーが出るため、どうやら問題は中括弧にある。

image.png

調べたところ中括弧は重ねることでエスケープできるらしい。ということでxに代入する文字列を" {{""id"" : ""{0}""}} "に修正して実行。

image.png

無事に想定通りの結果を得ることが出来た。

image.png

動作環境

  • UiPath.System.Activities v25.6.1
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?