JsonSetValue ÇÔ¼ö´Â JSONPath Ç¥Çö½ÄÀ» »ç¿ëÇÏ¿© ƯÁ¤ °æ·ÎÀÇ °ªÀ» º¯°æÇÑ´Ù.
int @JsonSetValue(string objectId, string jsonPath, object value);
int @JsonSetValue(string objectId, string jsonPath, object value, string dataType);
ÇÔ¼öÀÎÀÚ
string objectId : ´ë»ó JSON °´Ã¼ ID
string jsonPath : °ªÀ» ¼³Á¤ÇÒ JSONPath Ç¥Çö½Ä
object value : ¼³Á¤ÇÒ °ª
string dataType : °ªÀÇ µ¥ÀÌÅÍ Å¸ÀÔ, ¹Ì±âÀÔ ½Ã "string"
"string" : ¹®ÀÚ¿
"int", "long" : Á¤¼ö
"float", "double", "decimal" : ½Ç¼ö
"bool" : ºÒ¸®¾ð
"datetime" : ³¯Â¥/½Ã°£
"null" : null°ª
¹Ýȯ °ª
¼º°ø ½Ã 1
½ÇÆÐ ½Ã 0
Âü°í. JSONPath Ç¥Çö½Ä ¿¹
$.name: ÃÖ»óÀ§ °´Ã¼ÀÇ
"name" ¼Ó¼º
$.address.city: Áßø °´Ã¼ÀÇ "city" ¼Ó¼º
$.items[0]: ¹è¿ÀÇ Ã¹ ¹øÂ° ¿ä¼Ò
$.items[*]: ¸ðµç ¹è¿ ¿ä¼Ò
$..name: °´Ã¼ Æ®¸®¿¡¼ ¸ðµç "name" ¼Ó¼º
$.items[?(@.price>10)]:
Á¶°Ç¿¡ ¸Â´Â ¹è¿ ¿ä¼Ò (price°¡ 10º¸´Ù Å« ¿ä¼Ò)
¿¹Á¦ )
//¾Æ·¡ JSON ¹®ÀÚ¿ÀÌ string jsonString ÀÇ ÇöÀç
°ªÀ̶ó°í °¡Á¤
{
"person": {
"name":
"È«±æµ¿",
"contacts": [
{"type": "phone", "value": "010-1234-5678"},
{"type": "email", "value": "hong@example.com"}
]
}
}
string jsonObject = @JsonFromString(jsonString);
// JSONPath¸¦ »ç¿ëÇÏ¿© °ª
º¯°æ
@JsonSetValue(jsonObject, "$.person.name", "±èö¼ö", "string");
@JsonSetValue(jsonObject, "$.person.contacts[0].value", "010-9876-5432",
"string");
string result = @JsonToString(jsonObject);
//º¯°æµÈ jsonString °ª
{
"person": {
"name": "±èö¼ö",
"contacts": [
{"type": "phone",
"value": "010-9876-5432"},
{"type": "email", "value": "hong@example.com"}
]
}
}
¹öÀüÁ¤º¸
ÃÖÃÊÁö¿ø: 10.3.6.25
°ü·Ã Ç׸ñ)
JsonTemplateReplacePlaceholder